You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using C getopt_long a long option with optional_argument will have a value only if --flag=value syntax is used. --flag arg is parsed as a flag without an argument, and a free argument (I've verified that on macOS and Linux/glibc).
getopts' optflagopt behaves differently. It always takes the next argument as the value, even if the = syntax is not used.
This is problematic for me, because I can't faithfully port C getopt_long program to Rust. I also think it's a less useful behavior, because it makes it impossible to set a optflagopt flag without a value if it's not the last/only argument.
externcrate getopts;fnmain(){letmut o = getopts::Options::new();
o.optflagopt("","value","","");let m = o.parse(&["--value","foo","bar"]).unwrap();println!("with space {:?} + {:?}", m.opt_str("value"), m.free);let m = o.parse(&["--value=foo","bar"]).unwrap();println!("with = {:?} + {:?}", m.opt_str("value"), m.free);}
This prints:
with space Some("foo") + ["bar"]
with = Some("foo") + ["bar"]
I'd prefer it to parse as:
with space None + ["foo", "bar"]
with = Some("foo") + ["bar"]
The text was updated successfully, but these errors were encountered:
Simliar to rust-lang#49, this changes the parsing of short options to require no space between the option and argument. Now, `-aSomething` parse as an option with argument, and `-a Something` will parse as a present flag with a free non-option.
jridgewell
added a commit
to jridgewell/getopts-rust
that referenced
this issue
May 16, 2019
Similar to rust-lang#49, this changes the parsing of short options to require no space between the option and argument. Now, `-aSomething` parse as an option with argument, and `-a Something` will parse as a present flag with a free non-option.
This is a breaking change.
When using C
getopt_long
a long option withoptional_argument
will have a value only if--flag=value
syntax is used.--flag arg
is parsed as a flag without an argument, and a free argument (I've verified that on macOS and Linux/glibc).getopts'
optflagopt
behaves differently. It always takes the next argument as the value, even if the=
syntax is not used.This is problematic for me, because I can't faithfully port C
getopt_long
program to Rust. I also think it's a less useful behavior, because it makes it impossible to set aoptflagopt
flag without a value if it's not the last/only argument.This prints:
I'd prefer it to parse as:
The text was updated successfully, but these errors were encountered: