Skip to content

Commit 9d18551

Browse files
committed
fix: show command help only for invalid arguments
1 parent 77de5b5 commit 9d18551

Some content is hidden

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

51 files changed

+217
-173
lines changed

lib/commands/add-platform.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ 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> {
@@ -19,15 +19,15 @@ export class AddPlatformCommand extends ValidatePlatformCommandBase implements I
1919

2020
public async canExecute(args: string[]): Promise<ICanExecuteCommandOutput> {
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.failWithoutHelp(`Applications for platform ${arg} can not be built on this OS`);
3131
}
3232

3333
const output = await super.canExecuteCommandBase(arg);

lib/commands/appstore-list.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class ListiOSApps implements ICommand {
1717

1818
public async execute(args: string[]): Promise<void> {
1919
if (!this.$platformValidationService.isPlatformSupportedForOS(this.$devicePlatformsConstants.iOS, this.$projectData)) {
20-
this.$errors.fail(`Applications for platform ${this.$devicePlatformsConstants.iOS} can not be built on this OS`);
20+
this.$errors.failWithoutHelp(`Applications for platform ${this.$devicePlatformsConstants.iOS} can not be built on this OS`);
2121
}
2222

2323
let username = args[0];
@@ -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
@@ -83,7 +83,7 @@ export class PublishIOS implements ICommand {
8383
}
8484

8585
if (!this.$platformValidationService.isPlatformSupportedForOS(this.$devicePlatformsConstants.iOS, this.$projectData)) {
86-
this.$errors.fail(`Applications for platform ${this.$devicePlatformsConstants.iOS} can not be built on this OS`);
86+
this.$errors.failWithoutHelp(`Applications for platform ${this.$devicePlatformsConstants.iOS} can not be built on this OS`);
8787
}
8888

8989
return true;

lib/commands/build.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export abstract class BuildCommandBase extends ValidatePlatformCommandBase {
3030

3131
protected validatePlatform(platform: string): void {
3232
if (!this.$platformValidationService.isPlatformSupportedForOS(platform, this.$projectData)) {
33-
this.$errors.fail(`Applications for platform ${platform} can not be built on this OS`);
33+
this.$errors.failWithoutHelp(`Applications for platform ${platform} can not be built on this OS`);
3434
}
3535
}
3636

@@ -129,7 +129,7 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
129129
let result = await super.canExecuteCommandBase(platform, { notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true } });
130130
if (result.canExecute) {
131131
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);
132+
this.$errors.failWithHelp(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
133133
}
134134

135135
result = await super.validateArgs(args, platform);

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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ export class DebugPlatformCommand extends ValidatePlatformCommandBase implements
6060
this.$androidBundleValidatorHelper.validateNoAab();
6161

6262
if (!this.$platformValidationService.isPlatformSupportedForOS(this.platform, this.$projectData)) {
63-
this.$errors.fail(`Applications for platform ${this.platform} can not be built on this OS`);
63+
this.$errors.failWithoutHelp(`Applications for platform ${this.platform} can not be built on this OS`);
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 } });
@@ -105,18 +105,18 @@ export class DebugIOSCommand implements ICommand {
105105

106106
public async canExecute(args: string[]): Promise<ICanExecuteCommandOutput> {
107107
if (!this.$platformValidationService.isPlatformSupportedForOS(this.$devicePlatformsConstants.iOS, this.$projectData)) {
108-
this.$errors.fail(`Applications for platform ${this.$devicePlatformsConstants.iOS} can not be built on this OS`);
108+
this.$errors.failWithoutHelp(`Applications for platform ${this.$devicePlatformsConstants.iOS} can not be built on this OS`);
109109
}
110110

111111
const isValidTimeoutOption = this.isValidTimeoutOption();
112112
if (!isValidTimeoutOption) {
113-
this.$errors.fail(`Timeout option specifies the seconds NativeScript CLI will wait to find the inspector socket port from device's logs. Must be a number.`);
113+
this.$errors.failWithoutHelp(`Timeout option must be a number.`);
114114
}
115115

116116
if (this.$options.inspector) {
117117
const macOSWarning = await this.$sysInfo.getMacOSWarningMessage();
118118
if (macOSWarning && macOSWarning.severity === SystemWarningsSeverity.high) {
119-
this.$errors.fail(`You cannot use NativeScript Inspector on this OS. To use it, please update your OS.`);
119+
this.$errors.failWithoutHelp(`You cannot use NativeScript Inspector on this OS. To use it, please update your OS.`);
120120
}
121121
}
122122
const result = await this.debugPlatformCommand.canExecute(args);

lib/commands/deploy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ 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> {
@@ -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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ 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);

0 commit comments

Comments
 (0)