-
-
Notifications
You must be signed in to change notification settings - Fork 201
Expand file tree
/
Copy pathcommand-params.ts
More file actions
39 lines (31 loc) · 1.06 KB
/
command-params.ts
File metadata and controls
39 lines (31 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import {
ICommandParameter,
IStringParameterBuilder,
} from "./definitions/commands";
import { IInjector } from "./definitions/yok";
import { injector } from "./yok";
export class StringCommandParameter implements ICommandParameter {
public mandatory = false;
public errorMessage: string;
constructor(private $injector: IInjector) {}
public async validate(validationValue: string): Promise<boolean> {
if (!validationValue) {
if (this.errorMessage) {
this.$injector.resolve("errors").fail(this.errorMessage);
}
return false;
}
return true;
}
}
injector.register("stringParameter", StringCommandParameter);
export class StringParameterBuilder implements IStringParameterBuilder {
constructor(private $injector: IInjector) {}
public createMandatoryParameter(errorMsg: string): ICommandParameter {
const commandParameter = new StringCommandParameter(this.$injector);
commandParameter.mandatory = true;
commandParameter.errorMessage = errorMsg;
return commandParameter;
}
}
injector.register("stringParameterBuilder", StringParameterBuilder);