Rework complete command for Commander#125
Conversation
…ommands, and remove need to monkeypatch parse+parseAsync
🦋 Changeset detectedLatest commit: e7fad30 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
This is the UX experience for this PR with the tab-style combo % my-cmd --help
Usage: my-cmd [options] [command]
Options:
-V, --version output the version number
-h, --help display help for command
Commands:
serve [options] Start the server
complete [shell] Generate shell completion scripts
help [command] display help for command
% my-cmd complete --help
Usage: my-cmd complete [options] [shell]
Generate shell completion scripts
Arguments:
shell shell type (choices: "zsh", "bash", "fish", "powershell")
Options:
-h, --help display help for command
% my-cmd complete
error: missing required argument 'shell'
% my-cmd complete x
error: command-argument value 'x' is invalid for argument 'shell'. Allowed choices are zsh, bash, fish, powershell.This is the UX experience with a custom name ( % my-cmd --help
Usage: my-cmd [options] [command]
Options:
-V, --version output the version number
-h, --help display help for command
Commands:
serve [options] Start the server
completion <shell> Generate shell completion scripts
help [command] display help for command
% my-cmd complete --help
Usage: my-cmd complete complete -- [args...]
Generate completion suggestions
Options:
-h, --help display help for command
% my-cmd completion --help
Usage: my-cmd completion [options] <shell>
Generate shell completion scripts
Arguments:
shell Shell type for completion script (choices: "zsh", "bash", "fish", "powershell")
Options:
-h, --help display help for command
% my-cmd completion
error: missing required argument 'shell'
% my-cmd completion x
error: command-argument value 'x' is invalid for argument 'shell'. Allowed choices are zsh, bash, fish, powershell. |
commit: |
AmirSa12
left a comment
There was a problem hiding this comment.
Clean and very, very interesting refactor. thanks
would you want to document that in this PR or a separate one?
|
I'll make an issue to add the same optional config for the other two adapters |
| // Commander stripped `--`, so put it back for reparse | ||
| completeCommand.parse(['--', ...cmd.args], { from: 'user' }); | ||
| } else { | ||
| completionCommand.parse(shell !== undefined ? [shell] : [], { |
There was a problem hiding this comment.
I should pass cmd.args here too so that excess arguments can be detected.
I'll have a go in this PR. |
Rework Commander framework implementation to remove need to monkeypatch
.parse()+.parseAsync(), and optionally allow separate complete and completion commands. Commander allows customising name of other built-in commands and options likeversionandhelp.With separate commands, can show correct user facing syntax
completion <shell>and not need to detect difference between completion (complete <shell>) and complete (complete -- [args]).If maintainers ok with this approach, I'll mention the customisation option in the README.