Wrong help behavior for commands with proxy options
Opened this issue · 0 comments
This is a toy implementation of a command that is supposed to execute a sub-command for each package in a monorepo. It takes as arguments the sub-command to run in the context of each package, and an optional flag to exclude certain packages from the process.
export class WorkspaceEachCommand extends Command<BaseContext> {
static paths = [["each"]];
exclusions = Option.Array("-x,--exclude");
subcommand = Option.Proxy();
async execute(): Promise<number | void> {
const { stdout } = this.context;
const { exclusions, subcommand } = this;
stdout.write(JSON.stringify({ exclusions, subcommand }));
}
The usage (after taking into account #85, having the flags preceding the command) would be:
$ mytool -x ugly-package -x other-package-i-dont-like each do-something-interesting
{"exclusions":["ugly-package","other-package-i-dont-like"],"subcommand":["do-something-interesting"]}
This works correctly, or at least according to the expectations lined out in #85. If I try to get help for this command, though, things go wrong:
$ mytool each --help
{"subcommand":["--help"]}
Inverting the command and the flag also goes wrong – for different reasons:
$ mytool --help each
Unknown Syntax Error: Extraneous positional argument ("each").
$ mytool -h
If I type a wrong command, the help text suggests the wrong syntax, with the flags after the command. Given how the usage
function is structured, I think it would show up also in the help for the single command, if it could be accessed.
$ mytool wrong
Unknown Syntax Error: Command not found; did you mean one of:
0. mytool -h
1. mytool -v
2. mytool each [-x,--exclude #0] ...
While running wrong
Any suggestions for that?