-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3 leading hyphens for options (---long
)
#3309
Comments
Some extra context for anyone else, this is an upgrade from clap2 to clap3 and clap2 seemed to allow arbitrary number of leading use clap::{App, Arg};
fn main() {
let matches = build_app().get_matches();
dbg!(matches);
}
fn build_app() -> App<'static, 'static> {
App::new("myapp")
.version("3.0")
.about("Tests completions")
.arg(
Arg::with_name("file")
.long("file")
.takes_value(true)
.help("some input file"),
)
} $ cargo run -- -----file foo
Compiling test-clap v0.1.0 (/home/epage/src/personal/test-clap)
Finished dev [unoptimized + debuginfo] target(s) in 0.42s
Running `target/debug/test-clap -----file foo`
[src/main.rs:5] matches = ArgMatches {
args: {
"file": MatchedArg {
occurs: 1,
indices: [
2,
],
vals: [
"foo",
],
},
},
subcommand: None,
usage: Some(
"USAGE:\n test-clap [OPTIONS]",
),
} |
Any change to our handling of leading hyphens would be a breaking change and would have to wait until clap 4. We also have plans to pull out the lexer (#2915) and allow plugging in custom lexers (#1210).
This implies with clap2 you support exclusively 3 hyphens for some arguments. Have a small, reproducible example of how you did it? I've tried some ideas but haven't. I'd overall recommend this approach for the short term as anything else is unlikely to be available until clap 4. |
Ah yeah, that's important context indeed. That was how we were supporting it before.
Sorry for being unclear. We don't have that right now. So in that sense, we can actually model this behavior a bit better in clap 3 than in clap 2.
That makes sense. We'll stick with the workaround for now! Thank you for your response! |
Trying to decide what we should do with this issue moving forward. So far, the options seem to be
Thoughts? |
That is indeed a weird thing about my proposal. But I think it makes sense to reject a single Alternatively, the trimming of Regarding the options you present:
Nevertheless, I understand if you want to close this because there is a fairly viable workaround and there is no short term solution.
As a side note: I think it's good that the clap 2 behavior is gone and wouldn't want it back unless it's optional. |
Note that for #1210 I'm more calling out the generalized solution I proposed in the comments (was just being lazy). I agree about it being weird that If we removed trimming and made
I'm less concerned with "no short term solution" and more with "is any new solution within scope". As long as we feel there is room for a solution within the scope of clap, I'm fine leaving an issue open even if it is longer in the resolving. |
This is a step towards clap-rs#3309. We want to make longs and long aliases more consistent in how they handle leading dashes. There is more flexibility offered in not stripping and it matches the v3 short behavior of only taking the non-dash form. This starts the process by disallowing it completely so people will catch problems with it and remove their existing leading dashes. In a subsequent breaking release we can remove the debug assert and allow triple-leading dashes.
Please complete the following tasks
Clap Version
3.0.7
Describe your use case
In uutils/coreutils, we are trying to move to clap 3. Some of the original GNU utilities have long options with 3 leading hyphens. This is done because these flags are undocumented and only used for testing purposes. Two examples are:
We would like to support these with clap 3.
Describe the solution you'd like
The ideal solution would be if I could use a leading hyphen in the string passed to
Arg::long
, however, all leading hyphens are stripped here:Therefore, I would like to propose that only the first 2 hyphens would be stripped. So this
App
:would be executed with
This would technically be a breaking change, but I think that there isn't much (if any) code that passes long arguments with more than 2 leading hyphens.
Alternatives, if applicable
I think I have found a workaround using
alias
, which does not strip leading hyphens. So the workaround looks like this:However, this supports both 2 and 3 leading hyphens and is a bit awkward.
Additional Context
Finally, I just want to say that clap 3 has been fantastic so far and the transition is going very smoothly!
The text was updated successfully, but these errors were encountered: