diff --git a/lib/common/services/commands-service.ts b/lib/common/services/commands-service.ts index 315bbfa6e1..f46e63e4b1 100644 --- a/lib/common/services/commands-service.ts +++ b/lib/common/services/commands-service.ts @@ -29,15 +29,6 @@ export class CommandsService implements ICommandsService { private $extensibilityService: IExtensibilityService, private $optionsTracker: IOptionsTracker, private $projectDataService: IProjectDataService) { - let projectData = null; - try { - projectData = this.$projectDataService.getProjectData(); - } catch (err) { - this.$logger.trace(`Error while trying to get project data. More info: ${err}`); - } - - this.$options.setupOptions(projectData); - this.$options.printMessagesForDeprecatedOptions(this.$logger); } public allCommands(opts: { includeDevCommands: boolean }): string[] { @@ -114,8 +105,17 @@ export class CommandsService implements ICommandsService { private async tryExecuteCommandAction(commandName: string, commandArguments: string[]): Promise { const command = this.$injector.resolveCommand(commandName); - if (!command || (command && !command.isHierarchicalCommand)) { - this.$options.validateOptions(command ? command.dashedOptions : null); + if (!command || !command.isHierarchicalCommand) { + let projectData = null; + try { + projectData = this.$projectDataService.getProjectData(); + } catch (err) { + this.$logger.trace(`Error while trying to get project data. More info: ${err}`); + } + + const dashedOptions = command ? command.dashedOptions : null; + this.$options.validateOptions(dashedOptions, projectData); + this.$options.printMessagesForDeprecatedOptions(this.$logger); } return this.canExecuteCommand(commandName, commandArguments); diff --git a/lib/declarations.d.ts b/lib/declarations.d.ts index 24e53f6c37..9a96673a2e 100644 --- a/lib/declarations.d.ts +++ b/lib/declarations.d.ts @@ -503,7 +503,7 @@ interface IAndroidBundleOptions { interface IOptions extends IRelease, IDeviceIdentifier, IJustLaunch, IAvd, IAvailableDevices, IProfileDir, IHasEmulatorOption, IBundleString, IPlatformTemplate, IHasEmulatorOption, IClean, IProvision, ITeamIdentifier, IAndroidReleaseOptions, IAndroidBundleOptions, INpmInstallConfigurationOptions, IPort, IEnvOptions, IPluginSeedOptions, IGenerateOptions { argv: IYargArgv; - validateOptions(commandSpecificDashedOptions?: IDictionary): void; + validateOptions(commandSpecificDashedOptions?: IDictionary, projectData?: IProjectData): void; options: IDictionary; shorthands: string[]; /** @@ -573,7 +573,6 @@ interface IOptions extends IRelease, IDeviceIdentifier, IJustLaunch, IAvd, IAvai performance: Object; cleanupLogFile: string; workflow: any; - setupOptions(projectData: IProjectData): void; printMessagesForDeprecatedOptions(logger: ILogger): void; } diff --git a/lib/options.ts b/lib/options.ts index 01936ee917..8083b69425 100644 --- a/lib/options.ts +++ b/lib/options.ts @@ -21,7 +21,12 @@ export class Options { public options: IDictionary; - public setupOptions(projectData: IProjectData): void { + public setupOptions(projectData: IProjectData, commandSpecificDashedOptions?: IDictionary): void { + if (commandSpecificDashedOptions) { + _.extend(this.options, commandSpecificDashedOptions); + this.setArgv(); + } + if (this.argv.release && this.argv.hmr) { this.$errors.failWithoutHelp("The options --release and --hmr cannot be used simultaneously."); } @@ -173,12 +178,8 @@ export class Options { return this.argv[optionName]; } - public validateOptions(commandSpecificDashedOptions?: IDictionary): void { - if (commandSpecificDashedOptions) { - _.extend(this.options, commandSpecificDashedOptions); - this.setArgv(); - } - + public validateOptions(commandSpecificDashedOptions?: IDictionary, projectData?: IProjectData): void { + this.setupOptions(projectData, commandSpecificDashedOptions); const parsed = Object.create(null); // DO NOT REMOVE { } as when they are missing and some of the option values is false, the each stops as it thinks we have set "return false". _.each(_.keys(this.argv), optionName => { diff --git a/test/options.ts b/test/options.ts index 1727991746..444fbf444b 100644 --- a/test/options.ts +++ b/test/options.ts @@ -325,7 +325,7 @@ describe("options", () => { it(`should pass correctly when ${testCase.name} and useLegacyWorkflow is ${useLegacyWorkflow}`, () => { (testCase.args || []).forEach(arg => process.argv.push(arg)); - const options = createOptions(testInjector); + const options: any = createOptions(testInjector); const projectData = { useLegacyWorkflow }; options.setupOptions(projectData); @@ -359,7 +359,7 @@ describe("options", () => { errors.failWithoutHelp = (error: string) => actualError = error; (testCase.args || []).forEach(arg => process.argv.push(arg)); - const options = createOptions(testInjector); + const options: any = createOptions(testInjector); options.setupOptions(null); (testCase.args || []).forEach(arg => process.argv.pop());