Skip to content

Commit 58417c8

Browse files
committed
fix(citty-adapter): dont throw an error when there is no subcommand
1 parent 9aa80ef commit 58417c8

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

.changeset/busy-clocks-serve.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@bomb.sh/tab': patch
3+
---
4+
5+
fix: citty should not throw an error when there is no subcommand

src/citty.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,6 @@ export default async function tab<TArgs extends ArgsDef>(
127127
}
128128

129129
const subCommands = await resolve(instance.subCommands);
130-
if (!subCommands) {
131-
throw new Error('Invalid or missing subCommands.');
132-
}
133130

134131
const isPositional = isConfigPositional(instance);
135132

@@ -149,11 +146,13 @@ export default async function tab<TArgs extends ArgsDef>(
149146
}
150147
}
151148

152-
await handleSubCommands(
153-
subCommands,
154-
undefined,
155-
completionConfig?.subCommands
156-
);
149+
if (subCommands) {
150+
await handleSubCommands(
151+
subCommands,
152+
undefined,
153+
completionConfig?.subCommands
154+
);
155+
}
157156

158157
if (instance.args) {
159158
for (const [argName, argConfig] of Object.entries(instance.args)) {
@@ -243,7 +242,11 @@ export default async function tab<TArgs extends ArgsDef>(
243242
},
244243
});
245244

246-
subCommands.complete = completeCommand;
245+
if (!subCommands) {
246+
instance.subCommands = { complete: completeCommand };
247+
} else {
248+
subCommands.complete = completeCommand;
249+
}
247250

248251
return t;
249252
}

0 commit comments

Comments
 (0)