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

Playground #1134

Merged
merged 4 commits into from
Sep 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ interface IDoctorService {
* @param configOptions: defines if the result should be tracked by Analytics
* @returns {Promise<void>}
*/
printWarnings(configOptions?: { trackResult: boolean, projectDir?: string, runtimeVersion?: string }): Promise<void>;
printWarnings(configOptions?: { trackResult: boolean, projectDir?: string, runtimeVersion?: string, options?: ICommonOptions }): Promise<void>;
/**
* Runs the setup script on host machine
* @returns {Promise<ISpawnResult>}
Expand Down
21 changes: 20 additions & 1 deletion definitions/commands.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface ICommand extends ICommandOptions {
// One possible case where you can use this method is when you have two commandParameters, neither of them is mandatory,
// but at least one of them is required. Used in prop|add, prop|set, etc. commands as their logic is complicated and
// default validation in CommandsService is not applicable.
canExecute?(args: string[]): Promise<boolean>;
canExecute?(args: string[]): Promise<boolean | ICanExecuteCommandOutput>;
completionData?: string[];
dashedOptions?: IDictionary<IDashedOption>;
isHierarchicalCommand?: boolean;
Expand All @@ -23,6 +23,25 @@ interface ICommand extends ICommandOptions {
postCommandAction?(args: string[]): Promise<void>;
}

interface ICanExecuteCommandOutput {
canExecute: boolean;
/**
* In case when canExecute method returns false, the help of the command is printed.
* In case when canExecute method returns false and suppressCommandHelp is true, the command's help will not be printed.
*/
suppressCommandHelp?: boolean;
}

interface ICanExecuteCommandOptions {
validateOptions?: boolean;
notConfiguredEnvOptions?: INotConfiguredEnvOptions;
}

interface INotConfiguredEnvOptions {
hideSyncToPreviewAppOption?: boolean;
hideCloudBuildOption?: boolean;
}

interface IDynamicCommand extends ICommand { }

interface ISimilarCommand {
Expand Down
8 changes: 4 additions & 4 deletions mobile/mobile-core/devices-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,19 +558,19 @@ export class DevicesService extends EventEmitter implements Mobile.IDevicesServi

if (platform && deviceOption) {
this._platform = this.getPlatform(deviceInitOpts.platform);
await this.detectCurrentlyAttachedDevices(deviceInitOpts);
await this.startLookingForDevices(deviceInitOpts);
this._device = await this.getDevice(deviceOption);
if (this._device.deviceInfo.platform !== this._platform) {
this.$errors.fail(constants.ERROR_CANNOT_RESOLVE_DEVICE);
}
this.$logger.warn("Your application will be deployed only on the device specified by the provided index or identifier.");
} else if (!platform && deviceOption) {
await this.detectCurrentlyAttachedDevices(deviceInitOpts);
await this.startLookingForDevices(deviceInitOpts);
this._device = await this.getDevice(deviceOption);
this._platform = this._device.deviceInfo.platform;
} else if (platform && !deviceOption) {
this._platform = this.getPlatform(platform);
await this.detectCurrentlyAttachedDevices(deviceInitOpts);
await this.startLookingForDevices(deviceInitOpts);
} else {
// platform and deviceId are not specified
if (deviceInitOpts.skipInferPlatform) {
Expand All @@ -581,7 +581,7 @@ export class DevicesService extends EventEmitter implements Mobile.IDevicesServi
await this.startLookingForDevices(deviceInitOpts);
}
} else {
await this.detectCurrentlyAttachedDevices(deviceInitOpts);
await this.startLookingForDevices(deviceInitOpts);

const devices = this.getDeviceInstances();
const platforms = _(devices)
Expand Down
18 changes: 12 additions & 6 deletions services/commands-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ export class CommandsService implements ICommandsService {
return this.$helpService.showCommandLineHelp({ commandName: this.beautifyCommandName(commandName), commandArguments });
}

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

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

public async tryExecuteCommand(commandName: string, commandArguments: string[]): Promise<void> {
if (await this.executeCommandAction(commandName, commandArguments, this.tryExecuteCommandAction)) {
const canExecuteResult: any = await this.executeCommandAction(commandName, commandArguments, this.tryExecuteCommandAction);
const canExecute = typeof canExecuteResult === "object" ? canExecuteResult.canExecute : canExecuteResult;
const suppressCommandHelp = typeof canExecuteResult === "object" ? canExecuteResult.suppressCommandHelp : false;

if (canExecute) {
await this.executeCommandAction(commandName, commandArguments, this.executeCommandUnchecked);
} else {
// If canExecuteCommand returns false, the command cannot be executed or there's no such command at all.
const command = this.$injector.resolveCommand(commandName);
if (command) {
// If command cannot be executed we should print its help.
await this.printHelp(commandName, commandArguments);
if (!suppressCommandHelp) {
// If command cannot be executed we should print its help.
await this.printHelp(commandName, commandArguments);
}
}
}
}

private async canExecuteCommand(commandName: string, commandArguments: string[], isDynamicCommand?: boolean): Promise<boolean> {
private async canExecuteCommand(commandName: string, commandArguments: string[], isDynamicCommand?: boolean): Promise<boolean | ICanExecuteCommandOutput> {
const command = this.$injector.resolveCommand(commandName);
const beautifiedName = helpers.stringReplaceAll(commandName, "|", " ");
if (command) {
Expand Down