Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cli: allow alias after global args, and recursive aliases
Our support for aliases is very naively implemented; it assumes the alias is the first argument in argv. It therefore fails to resolve aliases after global arguments such as `--at-op`. This patch fixes that by modifying the command defintion to have an "external subcommand" in the list of available commands. That make `clap` give us the remainder of the arguments when it runs into an unknown command. The first in the list will then be an alias or simply an unknown command. Thanks to @epage for the suggestion on in clap-rs/clap#3672. The only minor problem is that it doesn't seem possible to tell `clap` to parse global arguments that come after the external subcommand. To work around that, we manually merge any parsed global argument before the alias with any parsed global arguments after it. With the new structure, it was easy to handle recursive alias definitions, so I added support for that too. Closes #292.
- Loading branch information
1 parent
c5a312b
commit c10b9d8
Showing
3 changed files
with
212 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters