diff --git a/.changeset/busy-clocks-serve.md b/.changeset/busy-clocks-serve.md new file mode 100644 index 0000000..180525a --- /dev/null +++ b/.changeset/busy-clocks-serve.md @@ -0,0 +1,5 @@ +--- +'@bomb.sh/tab': patch +--- + +fix: citty should not throw an error when there is no subcommand diff --git a/src/citty.ts b/src/citty.ts index d3eb1a3..bd205cf 100644 --- a/src/citty.ts +++ b/src/citty.ts @@ -127,9 +127,6 @@ export default async function tab( } const subCommands = await resolve(instance.subCommands); - if (!subCommands) { - throw new Error('Invalid or missing subCommands.'); - } const isPositional = isConfigPositional(instance); @@ -149,11 +146,13 @@ export default async function tab( } } - await handleSubCommands( - subCommands, - undefined, - completionConfig?.subCommands - ); + if (subCommands) { + await handleSubCommands( + subCommands, + undefined, + completionConfig?.subCommands + ); + } if (instance.args) { for (const [argName, argConfig] of Object.entries(instance.args)) { @@ -243,7 +242,11 @@ export default async function tab( }, }); - subCommands.complete = completeCommand; + if (!subCommands) { + instance.subCommands = { complete: completeCommand }; + } else { + subCommands.complete = completeCommand; + } return t; }