-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathcommand-base.ts
34 lines (28 loc) · 1.69 KB
/
command-base.ts
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
export abstract class ValidatePlatformCommandBase {
constructor(protected $options: IOptions,
protected $platformsData: IPlatformsData,
protected $platformService: IPlatformService,
protected $projectData: IProjectData) { }
abstract allowedParameters: ICommandParameter[];
abstract execute(args: string[]): Promise<void>;
public async canExecuteCommandBase(platform: string, options?: ICanExecuteCommandOptions): Promise<ICanExecuteCommandOutput> {
options = options || {};
const validatePlatformOutput = await this.validatePlatformBase(platform, options.notConfiguredEnvOptions);
const canExecute = this.canExecuteCommand(validatePlatformOutput);
let result = { canExecute, suppressCommandHelp: !canExecute };
if (canExecute && options.validateOptions) {
const validateOptionsOutput = await this.$platformService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, platform);
result = { canExecute: validateOptionsOutput, suppressCommandHelp: false };
}
return result;
}
private async validatePlatformBase(platform: string, notConfiguredEnvOptions: INotConfiguredEnvOptions): Promise<IValidatePlatformOutput> {
const platformData = this.$platformsData.getPlatformData(platform, this.$projectData);
const platformProjectService = platformData.platformProjectService;
const result = await platformProjectService.validate(this.$projectData, this.$options, notConfiguredEnvOptions);
return result;
}
private canExecuteCommand(validatePlatformOutput: IValidatePlatformOutput): boolean {
return validatePlatformOutput && validatePlatformOutput.checkEnvironmentRequirementsOutput && validatePlatformOutput.checkEnvironmentRequirementsOutput.canExecute;
}
}