Commit 10c821c
committed
fix(command): move default command handling to parseCommand
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) {1 parent 929f30b commit 10c821c
1 file changed
+16
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1273 | 1273 | | |
1274 | 1274 | | |
1275 | 1275 | | |
1276 | | - | |
1277 | | - | |
| 1276 | + | |
| 1277 | + | |
1278 | 1278 | | |
1279 | 1279 | | |
1280 | 1280 | | |
| |||
2067 | 2067 | | |
2068 | 2068 | | |
2069 | 2069 | | |
| 2070 | + | |
| 2071 | + | |
| 2072 | + | |
| 2073 | + | |
| 2074 | + | |
| 2075 | + | |
| 2076 | + | |
| 2077 | + | |
| 2078 | + | |
| 2079 | + | |
| 2080 | + | |
| 2081 | + | |
| 2082 | + | |
| 2083 | + | |
2070 | 2084 | | |
2071 | 2085 | | |
2072 | 2086 | | |
| |||
2287 | 2301 | | |
2288 | 2302 | | |
2289 | 2303 | | |
2290 | | - | |
2291 | | - | |
2292 | | - | |
2293 | | - | |
2294 | | - | |
2295 | | - | |
2296 | | - | |
2297 | | - | |
2298 | | - | |
2299 | | - | |
2300 | | - | |
2301 | | - | |
2302 | | - | |
2303 | | - | |
2304 | | - | |
2305 | | - | |
2306 | | - | |
2307 | 2304 | | |
2308 | 2305 | | |
2309 | 2306 | | |
| |||
0 commit comments