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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 7 additions & 11 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 14 additions & 21 deletions
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

Lines changed: 3 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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

0 commit comments

Comments
 (0)