Summary
Running a group command with no subcommand prints the literal word undefined instead of that command's usage. Three dispatchers do this; two others in the same file already do the right thing.
$ wmux browser
Unknown browser command: undefined (exit 1)
$ wmux agent
Unknown agent command: undefined (exit 1)
$ wmux pane
Unknown pane subcommand: undefined (exit 1)
versus, in the same CLI:
$ wmux markdown
Usage: wmux markdown <file> | wmux markdown set <id> --content <text> [--title T] | --file <path> | wmux markdown get <id>
$ wmux config
Usage: wmux config <show|reload|path>
Verified on v0.46.0. Exit status is 1 in all five cases, so only the message differs.
Cause
Each of the three interpolates args[1] into the error without checking that it exists, so a missing subcommand is reported as an unknown one named undefined:
|
async function cmdBrowser(args: string[]): Promise<void> { |
|
const handler = BROWSER_CMDS[args[1]]; |
|
if (!handler) { console.error(`Unknown browser command: ${args[1]}`); process.exit(1); return; } |
|
print(await handler(args)); |
|
} |
|
async function cmdAgent(args: string[]): Promise<void> { |
|
const handler = AGENT_CMDS[args[1]]; |
|
if (!handler) { console.error(`Unknown agent command: ${args[1]}`); process.exit(1); return; } |
|
print(await handler(args)); |
|
} |
|
} else { |
|
console.error(`Unknown pane subcommand: ${sub}`); process.exit(1); |
|
} |
COMMAND_SPECS already carries the usage string these should fall back to, and fail() already exists to print it — which is how markdown and config get it right. wmux browser --help cannot fill the gap either, since browser is passthrough: true and --help is treated as text to send.
Why it is worth fixing
wmux browser on its own is the natural thing to type when you want to know the verbs. Getting undefined back reads like the CLI malfunctioned rather than like a usage error, and it is a dead end: nothing in the output points at wmux help browser, which is the route that does work.
Small, but it is the first thing a new user or a fresh agent hits when exploring the browser API.
Note
cmdBrowser is the same function touched by #153, so if you would rather this land there than as a separate change, say the word and I will fold it in — I kept it out to avoid widening the scope of a PR you had not looked at yet.
Summary
Running a group command with no subcommand prints the literal word
undefinedinstead of that command's usage. Three dispatchers do this; two others in the same file already do the right thing.versus, in the same CLI:
Verified on v0.46.0. Exit status is 1 in all five cases, so only the message differs.
Cause
Each of the three interpolates
args[1]into the error without checking that it exists, so a missing subcommand is reported as an unknown one namedundefined:wmux/src/cli/wmux.ts
Lines 143 to 147 in fae21a5
wmux/src/cli/wmux.ts
Lines 184 to 188 in fae21a5
wmux/src/cli/wmux.ts
Lines 204 to 206 in fae21a5
COMMAND_SPECSalready carries the usage string these should fall back to, andfail()already exists to print it — which is howmarkdownandconfigget it right.wmux browser --helpcannot fill the gap either, sincebrowserispassthrough: trueand--helpis treated as text to send.Why it is worth fixing
wmux browseron its own is the natural thing to type when you want to know the verbs. Gettingundefinedback reads like the CLI malfunctioned rather than like a usage error, and it is a dead end: nothing in the output points atwmux help browser, which is the route that does work.Small, but it is the first thing a new user or a fresh agent hits when exploring the browser API.
Note
cmdBrowseris the same function touched by #153, so if you would rather this land there than as a separate change, say the word and I will fold it in — I kept it out to avoid widening the scope of a PR you had not looked at yet.