Cannot combine flags and options when using short
Closed this issue · 3 comments
ysndr commented
When I specify short names for options and flags, i.e. -l, -f, -v <ARG>
I can combine the flag arguments as -lf
. However it's not possible to also specify -v in that form, i.e. -lfv <ARG>
is invalid.
While this will only be possible when there is zero or one value argument in the last position, it does not seem far fetched to expect this to work.
I assume this is a conflict with supporting -lARG
:
For short flags value can follow immediately: -fbar. (docs)
Reporducer
use bpaf::{Bpaf, Parser};
#[allow(dead_code)]
#[derive(Debug, Clone, Bpaf)]
struct Args {
#[bpaf(short, long)]
list: bool,
#[bpaf(short, long)]
force: bool,
#[bpaf(short, long)]
value: String,
}
fn main() {
let parsed = args().run();
println!("{parsed:?}");
}
# ✅ all separate
$ cargo run -q -- -l -f -v abc
Args { list: true, force: true, value: "abc" }
# ✅ flags combined
$ cargo run -q -- -lf -v abc
Args { list: true, force: true, value: "abc" }
# 💢 flags and option combined
$ cargo run -q -- -lfv abc
Error: expected --value=ARG, got -lfv. Pass --help for usage information
# 💢 weird error message when using '='
$ cargo run -q -- -lfv=abc
Error: expected --value=ARG, got fv=abc. Pass --help for usage information
ysndr commented
Example in the wild, ie. go cobra i guess:
gh repo view -w -b main
gh repo view -wb main
# but also
gh repo view -w -bmain
gh repo view -wbmain
pacak commented
Ack. I'll see if this can be supported without making things too complicated...
ysndr commented
Thanks for looking into it!