What is the problem this feature would solve?
USAGE reflects where a command is mounted; its examples don't — they're fixed strings written at construction. Mount one command in two places (own bin, and subcommand of a larger CLI) and its examples describe an invocation that doesn't work.
It can't be fixed in user land: a child is built before withSubcommands attaches it, so the path isn't knowable when withExamples runs. The only workaround is threading the mount path into every command factory by hand.
What is the feature you are proposing to solve the problem?
An overload of Command.withExamples taking (commandPath: ReadonlyArray<string>) => ReadonlyArray<Example>, resolved in buildHelpDoc, which already receives commandPath for the USAGE line. Additive — the array form is unchanged.
Command.withExamples(create, (path) => [
{ command: `${path.join(" ")} --yes`, description: "Take every default." },
])
What alternatives have you considered?
- Threading the mount path in by hand — what we do now: every command factory takes the path it's mounted at and interpolates it into its own examples. Works, but re-supplies what the parser already computes, and nothing checks the two agree.
- Prefixing examples at the mount site via the public
examples field and withExamples. Same information written in the same place, and it doesn't recurse into grandchildren.
- Auto-prefixing relative examples with the usage path. Nicest to write, but breaks every existing absolute example — would need its own combinator.
- A custom help renderer that rewrites examples against the path. Not available:
run takes only { version }.
What is the problem this feature would solve?
USAGE reflects where a command is mounted; its examples don't — they're fixed strings written at construction. Mount one command in two places (own bin, and subcommand of a larger CLI) and its examples describe an invocation that doesn't work.
It can't be fixed in user land: a child is built before
withSubcommandsattaches it, so the path isn't knowable whenwithExamplesruns. The only workaround is threading the mount path into every command factory by hand.What is the feature you are proposing to solve the problem?
An overload of
Command.withExamplestaking(commandPath: ReadonlyArray<string>) => ReadonlyArray<Example>, resolved inbuildHelpDoc, which already receivescommandPathfor the USAGE line. Additive — the array form is unchanged.What alternatives have you considered?
examplesfield andwithExamples. Same information written in the same place, and it doesn't recurse into grandchildren.runtakes only{ version }.