Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit 3e9e870

Browse files
author
Fatme
authored
Merge pull request #1134 from telerik/feature/playground
Playground
2 parents 8f8a1b6 + f24ceea commit 3e9e870

File tree

4 files changed

+37
-12
lines changed

4 files changed

+37
-12
lines changed

declarations.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,7 @@ interface IDoctorService {
13721372
* @param configOptions: defines if the result should be tracked by Analytics
13731373
* @returns {Promise<void>}
13741374
*/
1375-
printWarnings(configOptions?: { trackResult: boolean, projectDir?: string, runtimeVersion?: string }): Promise<void>;
1375+
printWarnings(configOptions?: { trackResult: boolean, projectDir?: string, runtimeVersion?: string, options?: ICommonOptions }): Promise<void>;
13761376
/**
13771377
* Runs the setup script on host machine
13781378
* @returns {Promise<ISpawnResult>}

definitions/commands.d.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface ICommand extends ICommandOptions {
1010
// One possible case where you can use this method is when you have two commandParameters, neither of them is mandatory,
1111
// but at least one of them is required. Used in prop|add, prop|set, etc. commands as their logic is complicated and
1212
// default validation in CommandsService is not applicable.
13-
canExecute?(args: string[]): Promise<boolean>;
13+
canExecute?(args: string[]): Promise<boolean | ICanExecuteCommandOutput>;
1414
completionData?: string[];
1515
dashedOptions?: IDictionary<IDashedOption>;
1616
isHierarchicalCommand?: boolean;
@@ -23,6 +23,25 @@ interface ICommand extends ICommandOptions {
2323
postCommandAction?(args: string[]): Promise<void>;
2424
}
2525

26+
interface ICanExecuteCommandOutput {
27+
canExecute: boolean;
28+
/**
29+
* In case when canExecute method returns false, the help of the command is printed.
30+
* In case when canExecute method returns false and suppressCommandHelp is true, the command's help will not be printed.
31+
*/
32+
suppressCommandHelp?: boolean;
33+
}
34+
35+
interface ICanExecuteCommandOptions {
36+
validateOptions?: boolean;
37+
notConfiguredEnvOptions?: INotConfiguredEnvOptions;
38+
}
39+
40+
interface INotConfiguredEnvOptions {
41+
hideSyncToPreviewAppOption?: boolean;
42+
hideCloudBuildOption?: boolean;
43+
}
44+
2645
interface IDynamicCommand extends ICommand { }
2746

2847
interface ISimilarCommand {

mobile/mobile-core/devices-service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,19 +558,19 @@ export class DevicesService extends EventEmitter implements Mobile.IDevicesServi
558558

559559
if (platform && deviceOption) {
560560
this._platform = this.getPlatform(deviceInitOpts.platform);
561-
await this.detectCurrentlyAttachedDevices(deviceInitOpts);
561+
await this.startLookingForDevices(deviceInitOpts);
562562
this._device = await this.getDevice(deviceOption);
563563
if (this._device.deviceInfo.platform !== this._platform) {
564564
this.$errors.fail(constants.ERROR_CANNOT_RESOLVE_DEVICE);
565565
}
566566
this.$logger.warn("Your application will be deployed only on the device specified by the provided index or identifier.");
567567
} else if (!platform && deviceOption) {
568-
await this.detectCurrentlyAttachedDevices(deviceInitOpts);
568+
await this.startLookingForDevices(deviceInitOpts);
569569
this._device = await this.getDevice(deviceOption);
570570
this._platform = this._device.deviceInfo.platform;
571571
} else if (platform && !deviceOption) {
572572
this._platform = this.getPlatform(platform);
573-
await this.detectCurrentlyAttachedDevices(deviceInitOpts);
573+
await this.startLookingForDevices(deviceInitOpts);
574574
} else {
575575
// platform and deviceId are not specified
576576
if (deviceInitOpts.skipInferPlatform) {
@@ -581,7 +581,7 @@ export class DevicesService extends EventEmitter implements Mobile.IDevicesServi
581581
await this.startLookingForDevices(deviceInitOpts);
582582
}
583583
} else {
584-
await this.detectCurrentlyAttachedDevices(deviceInitOpts);
584+
await this.startLookingForDevices(deviceInitOpts);
585585

586586
const devices = this.getDeviceInstances();
587587
const platforms = _(devices)

services/commands-service.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ export class CommandsService implements ICommandsService {
105105
return this.$helpService.showCommandLineHelp({ commandName: this.beautifyCommandName(commandName), commandArguments });
106106
}
107107

108-
private async executeCommandAction(commandName: string, commandArguments: string[], action: (_commandName: string, _commandArguments: string[]) => Promise<boolean>): Promise<boolean> {
108+
private async executeCommandAction(commandName: string, commandArguments: string[], action: (_commandName: string, _commandArguments: string[]) => Promise<boolean | ICanExecuteCommandOutput>): Promise<boolean> {
109109
return this.$errors.beginCommand(
110110
() => action.apply(this, [commandName, commandArguments]),
111111
() => this.printHelp(commandName, commandArguments));
112112
}
113113

114-
private async tryExecuteCommandAction(commandName: string, commandArguments: string[]): Promise<boolean> {
114+
private async tryExecuteCommandAction(commandName: string, commandArguments: string[]): Promise<boolean | ICanExecuteCommandOutput> {
115115
const command = this.$injector.resolveCommand(commandName);
116116
if (!command || (command && !command.isHierarchicalCommand)) {
117117
this.$options.validateOptions(command ? command.dashedOptions : null);
@@ -125,19 +125,25 @@ export class CommandsService implements ICommandsService {
125125
}
126126

127127
public async tryExecuteCommand(commandName: string, commandArguments: string[]): Promise<void> {
128-
if (await this.executeCommandAction(commandName, commandArguments, this.tryExecuteCommandAction)) {
128+
const canExecuteResult: any = await this.executeCommandAction(commandName, commandArguments, this.tryExecuteCommandAction);
129+
const canExecute = typeof canExecuteResult === "object" ? canExecuteResult.canExecute : canExecuteResult;
130+
const suppressCommandHelp = typeof canExecuteResult === "object" ? canExecuteResult.suppressCommandHelp : false;
131+
132+
if (canExecute) {
129133
await this.executeCommandAction(commandName, commandArguments, this.executeCommandUnchecked);
130134
} else {
131135
// If canExecuteCommand returns false, the command cannot be executed or there's no such command at all.
132136
const command = this.$injector.resolveCommand(commandName);
133137
if (command) {
134-
// If command cannot be executed we should print its help.
135-
await this.printHelp(commandName, commandArguments);
138+
if (!suppressCommandHelp) {
139+
// If command cannot be executed we should print its help.
140+
await this.printHelp(commandName, commandArguments);
141+
}
136142
}
137143
}
138144
}
139145

140-
private async canExecuteCommand(commandName: string, commandArguments: string[], isDynamicCommand?: boolean): Promise<boolean> {
146+
private async canExecuteCommand(commandName: string, commandArguments: string[], isDynamicCommand?: boolean): Promise<boolean | ICanExecuteCommandOutput> {
141147
const command = this.$injector.resolveCommand(commandName);
142148
const beautifiedName = helpers.stringReplaceAll(commandName, "|", " ");
143149
if (command) {

0 commit comments

Comments
 (0)