Skip to content

Commit 9320a1d

Browse files
Merge pull request #4933 from NativeScript/tachev/show-help-only-when-needed
fix: stop showing the command help hiding the actual error
2 parents fd56fc4 + b10de63 commit 9320a1d

File tree

119 files changed

+612
-406
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+612
-406
lines changed

lib/android-tools-info.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
9292
*/
9393
private printMessage(msg: string, showWarningsAsErrors: boolean): void {
9494
if (showWarningsAsErrors) {
95-
this.$errors.failWithoutHelp(msg);
95+
this.$errors.fail(msg);
9696
} else {
9797
this.$logger.warn(msg);
9898
}
@@ -104,7 +104,7 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
104104
if (userSpecifiedCompileSdk) {
105105
const androidCompileSdk = `${androidToolsInfo.ANDROID_TARGET_PREFIX}-${userSpecifiedCompileSdk}`;
106106
if (!_.includes(installedTargets, androidCompileSdk)) {
107-
this.$errors.failWithoutHelp(`You have specified '${userSpecifiedCompileSdk}' for compile sdk, but it is not installed on your system.`);
107+
this.$errors.fail(`You have specified '${userSpecifiedCompileSdk}' for compile sdk, but it is not installed on your system.`);
108108
}
109109

110110
return userSpecifiedCompileSdk;

lib/commands/add-platform.ts

+7-11
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,31 @@ export class AddPlatformCommand extends ValidatePlatformCommandBase implements I
99
$projectData: IProjectData,
1010
$platformsDataService: IPlatformsDataService,
1111
private $errors: IErrors) {
12-
super($options, $platformsDataService, $platformValidationService, $projectData);
13-
this.$projectData.initializeProjectData();
12+
super($options, $platformsDataService, $platformValidationService, $projectData);
13+
this.$projectData.initializeProjectData();
1414
}
1515

1616
public async execute(args: string[]): Promise<void> {
1717
await this.$platformCommandHelper.addPlatforms(args, this.$projectData, this.$options.frameworkPath);
1818
}
1919

20-
public async canExecute(args: string[]): Promise<ICanExecuteCommandOutput> {
20+
public async canExecute(args: string[]): Promise<boolean> {
2121
if (!args || args.length === 0) {
22-
this.$errors.fail("No platform specified. Please specify a platform to add");
22+
this.$errors.failWithHelp("No platform specified. Please specify a platform to add.");
2323
}
2424

2525
let canExecute = true;
2626
for (const arg of args) {
2727
this.$platformValidationService.validatePlatform(arg, this.$projectData);
2828

2929
if (!this.$platformValidationService.isPlatformSupportedForOS(arg, this.$projectData)) {
30-
this.$errors.fail(`Applications for platform ${arg} can not be built on this OS`);
30+
this.$errors.fail(`Applications for platform ${arg} cannot be built on this OS`);
3131
}
3232

33-
const output = await super.canExecuteCommandBase(arg);
34-
canExecute = canExecute && output.canExecute;
33+
canExecute = await super.canExecuteCommandBase(arg);
3534
}
3635

37-
return {
38-
canExecute,
39-
suppressCommandHelp: !canExecute
40-
};
36+
return canExecute;
4137
}
4238
}
4339

lib/commands/appstore-list.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class ListiOSApps implements ICommand {
3737
this.$logger.info("Seems you don't have any applications yet.");
3838
} else {
3939
const table: any = createTable(["Application Name", "Bundle Identifier", "In Flight Version"], applications.map(application => {
40-
const version = (application && application.versionSets && application.versionSets.length && application.versionSets[0].inFlightVersion && application.versionSets[0].inFlightVersion.version) || "";
40+
const version = (application && application.versionSets && application.versionSets.length && application.versionSets[0].inFlightVersion && application.versionSets[0].inFlightVersion.version) || "";
4141
return [application.name, application.bundleId, version];
4242
}));
4343

lib/commands/appstore-upload.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class PublishIOS implements ICommand {
7979

8080
public async canExecute(args: string[]): Promise<boolean> {
8181
if (!this.$hostInfo.isDarwin) {
82-
this.$errors.failWithoutHelp("iOS publishing is only available on Mac OS X.");
82+
this.$errors.fail("iOS publishing is only available on macOS.");
8383
}
8484

8585
if (!this.$platformValidationService.isPlatformSupportedForOS(this.$devicePlatformsConstants.iOS, this.$projectData)) {

lib/commands/build.ts

+14-21
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,13 @@ export abstract class BuildCommandBase extends ValidatePlatformCommandBase {
3434
}
3535
}
3636

37-
protected async validateArgs(args: string[], platform: string): Promise<ICanExecuteCommandOutput> {
38-
const canExecute = await this.validateArgsCore(args, platform);
39-
return {
40-
canExecute,
41-
suppressCommandHelp: false
42-
};
43-
}
44-
45-
private async validateArgsCore(args: string[], platform: string): Promise<boolean> {
37+
protected async validateArgs(args: string[], platform: string): Promise<boolean> {
4638
if (args.length !== 0) {
47-
return false;
39+
this.$errors.failWithHelp(`The arguments '${args.join(" ")}' are not valid for the current command.`);
4840
}
4941

5042
const result = await this.$platformValidationService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, platform);
43+
5144
return result;
5245
}
5346
}
@@ -72,20 +65,20 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
7265
await this.executeCore([this.$devicePlatformsConstants.iOS.toLowerCase()]);
7366
}
7467

75-
public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
68+
public async canExecute(args: string[]): Promise<boolean> {
7669
const platform = this.$devicePlatformsConstants.iOS;
7770
if (!this.$options.force) {
7871
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [platform] });
7972
}
8073

8174
super.validatePlatform(platform);
8275

83-
let result = await super.canExecuteCommandBase(platform, { notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true } });
84-
if (result.canExecute) {
85-
result = await super.validateArgs(args, platform);
76+
let canExecute = await super.canExecuteCommandBase(platform, { notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true } });
77+
if (canExecute) {
78+
canExecute = await super.validateArgs(args, platform);
8679
}
8780

88-
return result;
81+
return canExecute;
8982
}
9083
}
9184

@@ -120,22 +113,22 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
120113
}
121114
}
122115

123-
public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
116+
public async canExecute(args: string[]): Promise<boolean> {
124117
const platform = this.$devicePlatformsConstants.Android;
125118
if (!this.$options.force) {
126119
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [platform] });
127120
}
128121
this.$androidBundleValidatorHelper.validateRuntimeVersion(this.$projectData);
129-
let result = await super.canExecuteCommandBase(platform, { notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true } });
130-
if (result.canExecute) {
122+
let canExecute = await super.canExecuteCommandBase(platform, { notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true } });
123+
if (canExecute) {
131124
if (this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
132-
this.$errors.fail(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
125+
this.$errors.failWithHelp(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
133126
}
134127

135-
result = await super.validateArgs(args, platform);
128+
canExecute = await super.validateArgs(args, platform);
136129
}
137130

138-
return result;
131+
return canExecute;
139132
}
140133
}
141134

lib/commands/command-base.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ export abstract class ValidatePlatformCommandBase {
77
abstract allowedParameters: ICommandParameter[];
88
abstract execute(args: string[]): Promise<void>;
99

10-
public async canExecuteCommandBase(platform: string, options?: ICanExecuteCommandOptions): Promise<ICanExecuteCommandOutput> {
10+
public async canExecuteCommandBase(platform: string, options?: ICanExecuteCommandOptions): Promise<boolean> {
1111
options = options || {};
1212
const validatePlatformOutput = await this.validatePlatformBase(platform, options.notConfiguredEnvOptions);
1313
const canExecute = this.canExecuteCommand(validatePlatformOutput);
14-
let result = { canExecute, suppressCommandHelp: !canExecute };
14+
let result = canExecute;
1515

1616
if (canExecute && options.validateOptions) {
17-
const validateOptionsOutput = await this.$platformValidationService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, platform);
18-
result = { canExecute: validateOptionsOutput, suppressCommandHelp: false };
17+
result = await this.$platformValidationService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, platform);
1918
}
2019

2120
return result;

lib/commands/create-project.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class CreateProjectCommand implements ICommand {
3131
};
3232

3333
if ((this.$options.tsc || this.$options.ng || this.$options.vue || this.$options.js) && this.$options.template) {
34-
this.$errors.fail("You cannot use a flavor option like --ng, --vue, --tsc and --js together with --template.");
34+
this.$errors.failWithHelp("You cannot use a flavor option like --ng, --vue, --tsc and --js together with --template.");
3535
}
3636

3737
let projectName = args[0];

lib/commands/debug.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class DebugPlatformCommand extends ValidatePlatformCommandBase implements
5252
});
5353
}
5454

55-
public async canExecute(args: string[]): Promise<ICanExecuteCommandOutput> {
55+
public async canExecute(args: string[]): Promise<boolean> {
5656
if (!this.$options.force) {
5757
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [this.platform] });
5858
}
@@ -64,7 +64,7 @@ export class DebugPlatformCommand extends ValidatePlatformCommandBase implements
6464
}
6565

6666
if (this.$options.release) {
67-
this.$errors.fail("--release flag is not applicable to this command");
67+
this.$errors.failWithHelp("--release flag is not applicable to this command.");
6868
}
6969

7070
const result = await super.canExecuteCommandBase(this.platform, { validateOptions: true, notConfiguredEnvOptions: { hideCloudBuildOption: true, hideSyncToPreviewAppOption: true } });
@@ -103,7 +103,7 @@ export class DebugIOSCommand implements ICommand {
103103
return this.debugPlatformCommand.execute(args);
104104
}
105105

106-
public async canExecute(args: string[]): Promise<ICanExecuteCommandOutput> {
106+
public async canExecute(args: string[]): Promise<boolean> {
107107
if (!this.$platformValidationService.isPlatformSupportedForOS(this.$devicePlatformsConstants.iOS, this.$projectData)) {
108108
this.$errors.fail(`Applications for platform ${this.$devicePlatformsConstants.iOS} can not be built on this OS`);
109109
}
@@ -164,7 +164,7 @@ export class DebugAndroidCommand implements ICommand {
164164
public execute(args: string[]): Promise<void> {
165165
return this.debugPlatformCommand.execute(args);
166166
}
167-
public async canExecute(args: string[]): Promise<ICanExecuteCommandOutput> {
167+
public async canExecute(args: string[]): Promise<boolean> {
168168
const result = await this.debugPlatformCommand.canExecute(args);
169169
return result;
170170
}

lib/commands/deploy.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ export class DeployOnDeviceCommand extends ValidatePlatformCommandBase implement
1919
$platformsDataService: IPlatformsDataService,
2020
private $deployCommandHelper: DeployCommandHelper,
2121
private $androidBundleValidatorHelper: IAndroidBundleValidatorHelper) {
22-
super($options, $platformsDataService, $platformValidationService, $projectData);
23-
this.$projectData.initializeProjectData();
22+
super($options, $platformsDataService, $platformValidationService, $projectData);
23+
this.$projectData.initializeProjectData();
2424
}
2525

2626
public async execute(args: string[]): Promise<void> {
2727
const platform = args[0].toLowerCase();
2828
await this.$deployCommandHelper.deploy(platform);
2929
}
3030

31-
public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
31+
public async canExecute(args: string[]): Promise<boolean> {
3232
this.$androidBundleValidatorHelper.validateNoAab();
3333
if (!args || !args.length || args.length > 1) {
3434
return false;
@@ -39,7 +39,7 @@ export class DeployOnDeviceCommand extends ValidatePlatformCommandBase implement
3939
}
4040

4141
if (this.$mobileHelper.isAndroidPlatform(args[0]) && this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
42-
this.$errors.fail(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
42+
this.$errors.failWithHelp(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
4343
}
4444

4545
const result = await super.canExecuteCommandBase(args[0], { validateOptions: true });

lib/commands/generate.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class GenerateCommand implements ICommand {
1212
try {
1313
await run(this.executionOptions);
1414
} catch (error) {
15-
this.$errors.failWithoutHelp(error.message);
15+
this.$errors.fail(error.message);
1616
}
1717
}
1818

@@ -25,7 +25,7 @@ export class GenerateCommand implements ICommand {
2525

2626
private validateExecutionOptions() {
2727
if (!this.executionOptions.schematic) {
28-
this.$errors.fail(`The generate command requires a schematic name to be specified.`);
28+
this.$errors.failWithHelp(`The generate command requires a schematic name to be specified.`);
2929
}
3030
}
3131

lib/commands/platform-clean.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class CleanCommand implements ICommand {
1818

1919
public async canExecute(args: string[]): Promise<boolean> {
2020
if (!args || args.length === 0) {
21-
this.$errors.fail("No platform specified. Please specify a platform to clean");
21+
this.$errors.failWithHelp("No platform specified. Please specify a platform to clean.");
2222
}
2323

2424
_.each(args, platform => {

lib/commands/plugin/add-plugin.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ export class AddPluginCommand implements ICommand {
44
constructor(private $pluginsService: IPluginsService,
55
private $projectData: IProjectData,
66
private $errors: IErrors) {
7-
this.$projectData.initializeProjectData();
8-
}
7+
this.$projectData.initializeProjectData();
8+
}
99

1010
public async execute(args: string[]): Promise<void> {
1111
return this.$pluginsService.add(args[0], this.$projectData);
1212
}
1313

1414
public async canExecute(args: string[]): Promise<boolean> {
1515
if (!args[0]) {
16-
this.$errors.fail("You must specify plugin name.");
16+
this.$errors.failWithHelp("You must specify plugin name.");
1717
}
1818

1919
const installedPlugins = await this.$pluginsService.getAllInstalledPlugins(this.$projectData);
2020
const pluginName = args[0].toLowerCase();
2121
if (_.some(installedPlugins, (plugin: IPluginData) => plugin.name.toLowerCase() === pluginName)) {
22-
this.$errors.failWithoutHelp(`Plugin "${pluginName}" is already installed.`);
22+
this.$errors.fail(`Plugin "${pluginName}" is already installed.`);
2323
}
2424

2525
return true;

lib/commands/plugin/build-plugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class BuildPluginCommand implements ICommand {
5454

5555
public async canExecute(args: string[]): Promise<boolean> {
5656
if (!this.$fs.exists(path.join(this.pluginProjectPath, constants.PLATFORMS_DIR_NAME, "android"))) {
57-
this.$errors.failWithoutHelp("No plugin found at the current directory, or the plugin does not need to have its platforms/android components built into an `.aar`.");
57+
this.$errors.fail("No plugin found at the current directory, or the plugin does not need to have its platforms/android components built into an `.aar`.");
5858
}
5959

6060
return true;

lib/commands/plugin/create-plugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class CreatePluginCommand implements ICommand {
4242

4343
public async canExecute(args: string[]): Promise<boolean> {
4444
if (!args[0]) {
45-
this.$errors.fail("You must specify the plugin repository name.");
45+
this.$errors.failWithHelp("You must specify the plugin repository name.");
4646
}
4747

4848
return true;

lib/commands/plugin/remove-plugin.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ export class RemovePluginCommand implements ICommand {
55
private $errors: IErrors,
66
private $logger: ILogger,
77
private $projectData: IProjectData) {
8-
this.$projectData.initializeProjectData();
9-
}
8+
this.$projectData.initializeProjectData();
9+
}
1010

1111
public async execute(args: string[]): Promise<void> {
1212
return this.$pluginsService.remove(args[0], this.$projectData);
1313
}
1414

1515
public async canExecute(args: string[]): Promise<boolean> {
1616
if (!args[0]) {
17-
this.$errors.fail("You must specify plugin name.");
17+
this.$errors.failWithHelp("You must specify plugin name.");
1818
}
1919

2020
let pluginNames: string[] = [];
@@ -29,7 +29,7 @@ export class RemovePluginCommand implements ICommand {
2929

3030
const pluginName = args[0].toLowerCase();
3131
if (!_.some(pluginNames, name => name.toLowerCase() === pluginName)) {
32-
this.$errors.failWithoutHelp(`Plugin "${pluginName}" is not installed.`);
32+
this.$errors.fail(`Plugin "${pluginName}" is not installed.`);
3333
}
3434

3535
return true;

lib/commands/plugin/update-plugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class UpdatePluginCommand implements ICommand {
2929

3030
const pluginName = args[0].toLowerCase();
3131
if (!_.some(installedPluginNames, name => name.toLowerCase() === pluginName)) {
32-
this.$errors.failWithoutHelp(`Plugin "${pluginName}" is not installed.`);
32+
this.$errors.fail(`Plugin "${pluginName}" is not installed.`);
3333
}
3434

3535
return true;

lib/commands/prepare.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class PrepareCommand extends ValidatePlatformCommandBase implements IComm
2929
await this.$prepareController.prepare(prepareData);
3030
}
3131

32-
public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
32+
public async canExecute(args: string[]): Promise<boolean> {
3333
const platform = args[0];
3434
const result = await this.$platformCommandParameter.validate(platform) &&
3535
await this.$platformValidationService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, platform);

lib/commands/preview.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class PreviewCommand implements ICommand {
3838

3939
public async canExecute(args: string[]): Promise<boolean> {
4040
if (args && args.length) {
41-
this.$errors.fail(`The arguments '${args.join(" ")}' are not valid for the preview command.`);
41+
this.$errors.failWithHelp(`The ${args.length > 1 ? "arguments" : "argument"} '${args.join(" ")}' ${args.length > 1 ? "are" : "is"} not valid for the preview command.`);
4242
}
4343

4444
if (!this.$options.force) {

lib/commands/remove-platform.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export class RemovePlatformCommand implements ICommand {
66
private $platformCommandHelper: IPlatformCommandHelper,
77
private $platformValidationService: IPlatformValidationService,
88
private $projectData: IProjectData
9-
) {
9+
) {
1010
this.$projectData.initializeProjectData();
1111
}
1212

@@ -16,7 +16,7 @@ export class RemovePlatformCommand implements ICommand {
1616

1717
public async canExecute(args: string[]): Promise<boolean> {
1818
if (!args || args.length === 0) {
19-
this.$errors.fail("No platform specified. Please specify a platform to remove");
19+
this.$errors.failWithHelp("No platform specified. Please specify a platform to remove.");
2020
}
2121

2222
_.each(args, platform => {

0 commit comments

Comments
 (0)