Skip to content

Commit ba38e07

Browse files
committed
Validate platform in canExecute function
1 parent f95a53a commit ba38e07

File tree

6 files changed

+85
-8
lines changed

6 files changed

+85
-8
lines changed

lib/commands/build.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ export class BuildCommandBase {
77
executeCore(args: string[]): IFuture<void> {
88
return this.$platformService.buildPlatform(args[0]);
99
}
10+
11+
canExecuteCore(args: string[]): IFuture<boolean> {
12+
return (() => {
13+
this.$platformService.validatePlatform(args[0]);
14+
return true;
15+
}).future<boolean>()();
16+
}
1017
}
1118

1219
export class BuildIosCommand extends BuildCommandBase implements ICommand {
@@ -20,6 +27,10 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
2027
public execute(args: string[]): IFuture<void> {
2128
return this.executeCore([this.$platformsData.availablePlatforms.iOS]);
2229
}
30+
31+
public canExecute(args: string[]): IFuture<boolean> {
32+
return this.canExecuteCore([this.$platformsData.availablePlatforms.iOS]);
33+
}
2334
}
2435
$injector.registerCommand("build|ios", BuildIosCommand);
2536

@@ -35,5 +46,9 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
3546
public execute(args: string[]): IFuture<void> {
3647
return this.executeCore([this.$platformsData.availablePlatforms.Android]);
3748
}
49+
50+
public canExecute(args: string[]): IFuture<boolean> {
51+
return this.canExecuteCore([this.$platformsData.availablePlatforms.Android]);
52+
}
3853
}
3954
$injector.registerCommand("build|android", BuildAndroidCommand);

lib/commands/debug.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,45 @@
22
"use strict";
33

44
export class DebugPlatformCommand implements ICommand {
5-
constructor(private debugService: IDebugService) { }
5+
constructor(private debugService: IDebugService,
6+
private $platformService: IPlatformService) { }
67

78
execute(args: string[]): IFuture<void> {
89
return this.debugService.debug();
910
}
10-
11+
12+
public canExecuteCore(args: string[]): IFuture<boolean> {
13+
return (() => {
14+
this.$platformService.validatePlatform(args[0]);
15+
return true;
16+
}).future<boolean>()();
17+
}
18+
1119
allowedParameters: ICommandParameter[] = [];
1220
}
1321

1422
export class DebugIOSCommand extends DebugPlatformCommand {
15-
constructor(private $iOSDebugService: IDebugService) {
16-
super($iOSDebugService);
23+
constructor(private $iOSDebugService: IDebugService,
24+
$platformService: IPlatformService,
25+
private $platformsData: IPlatformsData) {
26+
super($iOSDebugService, $platformService);
27+
}
28+
29+
public canExecute(args: string[]): IFuture<boolean> {
30+
return this.canExecuteCore([this.$platformsData.availablePlatforms.iOS]);
1731
}
1832
}
1933
$injector.registerCommand("debug|ios", DebugIOSCommand);
2034

2135
export class DebugAndroidCommand extends DebugPlatformCommand {
22-
constructor(private $androidDebugService: IDebugService) {
23-
super($androidDebugService);
36+
constructor(private $androidDebugService: IDebugService,
37+
$platformService: IPlatformService,
38+
private $platformsData: IPlatformsData) {
39+
super($androidDebugService, $platformService);
40+
}
41+
42+
public canExecute(args: string[]): IFuture<boolean> {
43+
return this.canExecuteCore([this.$platformsData.availablePlatforms.Android]);
2444
}
2545
}
2646
$injector.registerCommand("debug|android", DebugAndroidCommand);

lib/commands/deploy.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ export class DeployOnDeviceCommand implements ICommand {
88
execute(args: string[]): IFuture<void> {
99
return this.$platformService.deployOnDevice(args[0]);
1010
}
11+
12+
public canExecute(args: string[]): IFuture<boolean> {
13+
return (() => {
14+
this.$platformService.validatePlatform(args[0]);
15+
return true;
16+
}).future<boolean>()();
17+
}
1118

1219
allowedParameters = [this.$platformCommandParameter];
1320
}

lib/commands/emulate.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ export class EmulateCommandBase {
77
executeCore(args: string[]): IFuture<void> {
88
return this.$platformService.deployOnEmulator(args[0]);
99
}
10+
11+
public canExecuteCore(args: string[]): IFuture<boolean> {
12+
return (() => {
13+
this.$platformService.validatePlatform(args[0]);
14+
return true;
15+
}).future<boolean>()();
16+
}
1017
}
1118

1219
export class EmulateIosCommand extends EmulateCommandBase implements ICommand {
@@ -20,6 +27,10 @@ export class EmulateIosCommand extends EmulateCommandBase implements ICommand {
2027
public execute(args: string[]): IFuture<void> {
2128
return this.executeCore([this.$platformsData.availablePlatforms.iOS]);
2229
}
30+
31+
public canExecute(args: string[]): IFuture<boolean> {
32+
return this.canExecuteCore([this.$platformsData.availablePlatforms.iOS]);
33+
}
2334
}
2435
$injector.registerCommand("emulate|ios", EmulateIosCommand);
2536

@@ -34,5 +45,9 @@ export class EmulateAndroidCommand extends EmulateCommandBase implements IComman
3445
public execute(args: string[]): IFuture<void> {
3546
return this.executeCore([this.$platformsData.availablePlatforms.Android]);
3647
}
48+
49+
public canExecute(args: string[]): IFuture<boolean> {
50+
return this.canExecuteCore([this.$platformsData.availablePlatforms.Android]);
51+
}
3752
}
3853
$injector.registerCommand("emulate|android", EmulateAndroidCommand);

lib/commands/prepare.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ export class PrepareCommand implements ICommand {
66
private $platformCommandParameter: ICommandParameter) { }
77

88
execute(args: string[]): IFuture<void> {
9+
return this.$platformService.preparePlatform(args[0]);
10+
}
11+
12+
public canExecute(args: string[]): IFuture<boolean> {
913
return (() => {
10-
this.$platformService.preparePlatform(args[0]).wait();
11-
}).future<void>()();
14+
this.$platformService.validatePlatform(args[0]);
15+
return true;
16+
}).future<boolean>()();
1217
}
1318

1419
allowedParameters = [this.$platformCommandParameter];

lib/commands/run.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ export class RunCommandBase {
77
public executeCore(args: string[]): IFuture<void> {
88
return this.$platformService.runPlatform(args[0]);
99
}
10+
11+
public canExecuteCore(args: string[]): IFuture<boolean> {
12+
return (() => {
13+
this.$platformService.validatePlatform(args[0]);
14+
return true;
15+
}).future<boolean>()();
16+
}
1017
}
1118

1219
export class RunIosCommand extends RunCommandBase implements ICommand {
@@ -20,6 +27,10 @@ export class RunIosCommand extends RunCommandBase implements ICommand {
2027
public execute(args: string[]): IFuture<void> {
2128
return this.executeCore([this.$platformsData.availablePlatforms.iOS]);
2229
}
30+
31+
public canExecute(args: string[]): IFuture<boolean> {
32+
return this.canExecuteCore([this.$platformsData.availablePlatforms.iOS]);
33+
}
2334
}
2435
$injector.registerCommand("run|ios", RunIosCommand);
2536

@@ -34,5 +45,9 @@ export class RunAndroidCommand extends RunCommandBase implements ICommand {
3445
public execute(args: string[]): IFuture<void> {
3546
return this.executeCore([this.$platformsData.availablePlatforms.Android]);
3647
}
48+
49+
public canExecute(args: string[]): IFuture<boolean> {
50+
return this.canExecuteCore([this.$platformsData.availablePlatforms.Android]);
51+
}
3752
}
3853
$injector.registerCommand("run|android", RunAndroidCommand);

0 commit comments

Comments
 (0)