Skip to content

Commit f2e06e8

Browse files
committed
fix default command type in subcommand
1 parent 58543b2 commit f2e06e8

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sigma/parse",
3-
"version": "0.51.0",
3+
"version": "0.52.0",
44
"exports": "./mod.ts",
55
"license": "MIT",
66
"tasks": {

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export interface ParseOptions {
156156
*/
157157
export interface CommandOptions {
158158
/** Default command to run when no arguments are provided to this subcommand */
159-
defaultCommand?: "help";
159+
defaultCommand?: string | "help";
160160
}
161161

162162
/**

tests/index_extra.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,24 @@ Deno.test("subcommand with custom description in @subCommand", () => {
188188
// This covers some merging logic in executeSubCommand
189189
App.parse(["sub"]);
190190
});
191+
192+
Deno.test("subcommand with string defaultCommand (points to another subcommand)", () => {
193+
@command
194+
class List2 {}
195+
196+
@command({ defaultCommand: "list2" })
197+
class List {
198+
@subCommand(List2)
199+
list2?: List2;
200+
}
201+
202+
@cli({ name: "app" })
203+
class App extends Args {
204+
@subCommand(List)
205+
list?: List;
206+
}
207+
208+
const result = App.parse(["list"]);
209+
assertEquals(result.list instanceof List, true);
210+
assertEquals(result.list?.list2 instanceof List2, true);
211+
});

0 commit comments

Comments
 (0)