Skip to content

fix: stop showing the command help hiding the actual error #4933

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 14, 2019
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
4 changes: 2 additions & 2 deletions lib/android-tools-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
*/
private printMessage(msg: string, showWarningsAsErrors: boolean): void {
if (showWarningsAsErrors) {
this.$errors.failWithoutHelp(msg);
this.$errors.fail(msg);
} else {
this.$logger.warn(msg);
}
Expand All @@ -104,7 +104,7 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
if (userSpecifiedCompileSdk) {
const androidCompileSdk = `${androidToolsInfo.ANDROID_TARGET_PREFIX}-${userSpecifiedCompileSdk}`;
if (!_.includes(installedTargets, androidCompileSdk)) {
this.$errors.failWithoutHelp(`You have specified '${userSpecifiedCompileSdk}' for compile sdk, but it is not installed on your system.`);
this.$errors.fail(`You have specified '${userSpecifiedCompileSdk}' for compile sdk, but it is not installed on your system.`);
}

return userSpecifiedCompileSdk;
Expand Down
18 changes: 7 additions & 11 deletions lib/commands/add-platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,31 @@ export class AddPlatformCommand extends ValidatePlatformCommandBase implements I
$projectData: IProjectData,
$platformsDataService: IPlatformsDataService,
private $errors: IErrors) {
super($options, $platformsDataService, $platformValidationService, $projectData);
this.$projectData.initializeProjectData();
super($options, $platformsDataService, $platformValidationService, $projectData);
this.$projectData.initializeProjectData();
}

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

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

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

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

const output = await super.canExecuteCommandBase(arg);
canExecute = canExecute && output.canExecute;
canExecute = await super.canExecuteCommandBase(arg);
}

return {
canExecute,
suppressCommandHelp: !canExecute
};
return canExecute;
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/commands/appstore-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class ListiOSApps implements ICommand {
this.$logger.info("Seems you don't have any applications yet.");
} else {
const table: any = createTable(["Application Name", "Bundle Identifier", "In Flight Version"], applications.map(application => {
const version = (application && application.versionSets && application.versionSets.length && application.versionSets[0].inFlightVersion && application.versionSets[0].inFlightVersion.version) || "";
const version = (application && application.versionSets && application.versionSets.length && application.versionSets[0].inFlightVersion && application.versionSets[0].inFlightVersion.version) || "";
return [application.name, application.bundleId, version];
}));

Expand Down
2 changes: 1 addition & 1 deletion lib/commands/appstore-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class PublishIOS implements ICommand {

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

if (!this.$platformValidationService.isPlatformSupportedForOS(this.$devicePlatformsConstants.iOS, this.$projectData)) {
Expand Down
35 changes: 14 additions & 21 deletions lib/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,13 @@ export abstract class BuildCommandBase extends ValidatePlatformCommandBase {
}
}

protected async validateArgs(args: string[], platform: string): Promise<ICanExecuteCommandOutput> {
const canExecute = await this.validateArgsCore(args, platform);
return {
canExecute,
suppressCommandHelp: false
};
}

private async validateArgsCore(args: string[], platform: string): Promise<boolean> {
protected async validateArgs(args: string[], platform: string): Promise<boolean> {
if (args.length !== 0) {
return false;
this.$errors.failWithHelp(`The arguments '${args.join(" ")}' are not valid for the current command.`);
}

const result = await this.$platformValidationService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, platform);

return result;
}
}
Expand All @@ -72,20 +65,20 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
await this.executeCore([this.$devicePlatformsConstants.iOS.toLowerCase()]);
}

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

super.validatePlatform(platform);

let result = await super.canExecuteCommandBase(platform, { notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true } });
if (result.canExecute) {
result = await super.validateArgs(args, platform);
let canExecute = await super.canExecuteCommandBase(platform, { notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true } });
if (canExecute) {
canExecute = await super.validateArgs(args, platform);
}

return result;
return canExecute;
}
}

Expand Down Expand Up @@ -120,22 +113,22 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
}
}

public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
public async canExecute(args: string[]): Promise<boolean> {
const platform = this.$devicePlatformsConstants.Android;
if (!this.$options.force) {
await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [platform] });
}
this.$androidBundleValidatorHelper.validateRuntimeVersion(this.$projectData);
let result = await super.canExecuteCommandBase(platform, { notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true } });
if (result.canExecute) {
let canExecute = await super.canExecuteCommandBase(platform, { notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true } });
if (canExecute) {
if (this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
this.$errors.fail(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
this.$errors.failWithHelp(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
}

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

return result;
return canExecute;
}
}

Expand Down
7 changes: 3 additions & 4 deletions lib/commands/command-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ export abstract class ValidatePlatformCommandBase {
abstract allowedParameters: ICommandParameter[];
abstract execute(args: string[]): Promise<void>;

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

if (canExecute && options.validateOptions) {
const validateOptionsOutput = await this.$platformValidationService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, platform);
result = { canExecute: validateOptionsOutput, suppressCommandHelp: false };
result = await this.$platformValidationService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, platform);
}

return result;
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/create-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class CreateProjectCommand implements ICommand {
};

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

let projectName = args[0];
Expand Down
8 changes: 4 additions & 4 deletions lib/commands/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class DebugPlatformCommand extends ValidatePlatformCommandBase implements
});
}

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

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

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

public async canExecute(args: string[]): Promise<ICanExecuteCommandOutput> {
public async canExecute(args: string[]): Promise<boolean> {
if (!this.$platformValidationService.isPlatformSupportedForOS(this.$devicePlatformsConstants.iOS, this.$projectData)) {
this.$errors.fail(`Applications for platform ${this.$devicePlatformsConstants.iOS} can not be built on this OS`);
}
Expand Down Expand Up @@ -164,7 +164,7 @@ export class DebugAndroidCommand implements ICommand {
public execute(args: string[]): Promise<void> {
return this.debugPlatformCommand.execute(args);
}
public async canExecute(args: string[]): Promise<ICanExecuteCommandOutput> {
public async canExecute(args: string[]): Promise<boolean> {
const result = await this.debugPlatformCommand.canExecute(args);
return result;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ export class DeployOnDeviceCommand extends ValidatePlatformCommandBase implement
$platformsDataService: IPlatformsDataService,
private $deployCommandHelper: DeployCommandHelper,
private $androidBundleValidatorHelper: IAndroidBundleValidatorHelper) {
super($options, $platformsDataService, $platformValidationService, $projectData);
this.$projectData.initializeProjectData();
super($options, $platformsDataService, $platformValidationService, $projectData);
this.$projectData.initializeProjectData();
}

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

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

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

const result = await super.canExecuteCommandBase(args[0], { validateOptions: true });
Expand Down
4 changes: 2 additions & 2 deletions lib/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class GenerateCommand implements ICommand {
try {
await run(this.executionOptions);
} catch (error) {
this.$errors.failWithoutHelp(error.message);
this.$errors.fail(error.message);
}
}

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

private validateExecutionOptions() {
if (!this.executionOptions.schematic) {
this.$errors.fail(`The generate command requires a schematic name to be specified.`);
this.$errors.failWithHelp(`The generate command requires a schematic name to be specified.`);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/commands/platform-clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class CleanCommand implements ICommand {

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

_.each(args, platform => {
Expand Down
8 changes: 4 additions & 4 deletions lib/commands/plugin/add-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ export class AddPluginCommand implements ICommand {
constructor(private $pluginsService: IPluginsService,
private $projectData: IProjectData,
private $errors: IErrors) {
this.$projectData.initializeProjectData();
}
this.$projectData.initializeProjectData();
}

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

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

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

return true;
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/plugin/build-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class BuildPluginCommand implements ICommand {

public async canExecute(args: string[]): Promise<boolean> {
if (!this.$fs.exists(path.join(this.pluginProjectPath, constants.PLATFORMS_DIR_NAME, "android"))) {
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`.");
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`.");
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/plugin/create-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class CreatePluginCommand implements ICommand {

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

return true;
Expand Down
8 changes: 4 additions & 4 deletions lib/commands/plugin/remove-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ export class RemovePluginCommand implements ICommand {
private $errors: IErrors,
private $logger: ILogger,
private $projectData: IProjectData) {
this.$projectData.initializeProjectData();
}
this.$projectData.initializeProjectData();
}

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

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

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

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

return true;
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/plugin/update-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class UpdatePluginCommand implements ICommand {

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

return true;
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class PrepareCommand extends ValidatePlatformCommandBase implements IComm
await this.$prepareController.prepare(prepareData);
}

public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
public async canExecute(args: string[]): Promise<boolean> {
const platform = args[0];
const result = await this.$platformCommandParameter.validate(platform) &&
await this.$platformValidationService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, platform);
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class PreviewCommand implements ICommand {

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

if (!this.$options.force) {
Expand Down
4 changes: 2 additions & 2 deletions lib/commands/remove-platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class RemovePlatformCommand implements ICommand {
private $platformCommandHelper: IPlatformCommandHelper,
private $platformValidationService: IPlatformValidationService,
private $projectData: IProjectData
) {
) {
this.$projectData.initializeProjectData();
}

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

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

_.each(args, platform => {
Expand Down
Loading