User-configurable aliases #430
Unanswered
CGamesPlay
asked this question in
Q&A
Replies: 1 comment 1 reply
-
|
I think the easiest way would be for you to do the replacement yourself before feeding the input to let args = std::env::args().into_iter().collect::<Vec<_>>(); // or args_os
let args = expand_aliases(args)?; // fn expand_aliases(args: Vec<String>) -> Vec<String>
let opts = match Options::run_inner(args) {
Ok(opts) => opts,
Err(err) => {
err.print_message(120);
std::process::exit(err.exit_code())
}It's an interesting problem I never thought about it before. Will try to add a better solution to the next version I'm working on. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I want to add user-configurable aliases to my CLI, like git has. The aliases should work like this: the first argument is typically a command. If no command matches, it should check the alias list. If an alias matches, it should replace that positional argument with the expansion of the alias and continue parsing arguments (this process might fail due to bad configuration, which is OK).
For example, let's say I have a program which accepts a
createsubcommand which itself has arguments for--foo,--barand--baz. I want to be able to define an alias ofupthat expands tocreate --foo=yes --bar=12, such that I can invokemyprog up --baz=neverand it's equivalent tomyprog create --foo=yes --bar=12 --baz=never. Of particular concern is completion support, somyprog up --bshould complete to--baz, since that's a valid, unused option in the expanded command.Is this possible in bpaf? I looked through the examples and didn't see anything relevant, and I'm not really sure how I can implement this "the alias replaces itself with its expansion" in the parser.
Beta Was this translation helpful? Give feedback.
All reactions