fix(command): move default command handling to parseCommand#860
Merged
Conversation
diff --git c/command/command.ts i/command/command.ts index 92c9dfb..0eef8c2 100644 --- c/command/command.ts +++ i/command/command.ts @@ -1273,8 +1273,8 @@ export class Command< /** * Set default command. * - * The default command is executed when the program was called without any - * arguments. + * The default command is executed when the command was called without any + * additional arguments. * * @param name Name of the default command. */ @@ -2068,6 +2068,20 @@ export class Command< this.registerDefaults(); this.props.rawArgs = ctx.unknown.slice(); + if (!ctx.unknown.length && this.settings.defaultCommand) { + const defaultCommand = this.getCommand(this.settings.defaultCommand, true); + + if (!defaultCommand) { + throw new DefaultCommandNotFoundError( + this.settings.defaultCommand, + this.getCommands(), + ); + } + defaultCommand.props.globalParent = this; + + return defaultCommand.parseCommand(ctx); + } + if (this.settings.useRawArgs) { await this.parseEnvVars(ctx, this.builder.envVars); return await this.execute(ctx.env, ctx.unknown); @@ -2288,23 +2302,6 @@ export class Command< options: Record<string, unknown>, args: Array<unknown>, ): Promise<CommandResult> { - if ( - this.settings.defaultCommand && !args.length && - !Object.keys(options).length - ) { - const cmd = this.getCommand(this.settings.defaultCommand, true); - - if (!cmd) { - throw new DefaultCommandNotFoundError( - this.settings.defaultCommand, - this.getCommands(), - ); - } - cmd.props.globalParent = this; - - return cmd.execute(options, args); - } - await this.executeGlobalAction(options, args); if (this.settings.actionHandler) {
10c821c to
86d52c6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.