-
-
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
allow app names, options and subcommands with hyphens when using the macro #321
Comments
@flying-sheep the macro is still a work in progress, so thanks for reporting this! @james-darkfox ideas? As a hacky work-around until this bug is fixed, you should be able to use a combination of the macro and traditional builder pattern (and builder pattern is just as fast as macro performance wise, just more verbose): let app = clap_app!(myapp =>
...
(@arg group_by: -g --group-by +takes_value "foo")
)
.arg(Arg::with_name("group_by")
.short("g")
.long("group-by")
.takes_value(true)
.help("foo")); |
ha, i think for a one-time construction like here, any performance is good enough 😄 |
If parsing speed isn't a concern you can achieve a similarly less verbose using the "usage style." This isn't to say the usage strings are slow, they're still quite fast, just not quite as fast as the builder pattern (or macro which simply expands to the builder). .arg_from_usage("-g, --group-by [group_by] 'foo'") |
@flying-sheep This is a limitation of the macro muncher I'm using here. Please use @kbknapp Not a bug. Limitation in the macro. I might be able to extend the macro muncher to concat these kinds of tokens but there will need to be some distinction between |
@kbknapp I've already mentioned this issue in other issues (not tracking them down right now). And the case for |
@james-darkfox yep, I remember you saying that now, my bad! I'd totally forgotten about that. We can remove the bug label, and just leave this issue open for tracking purposes. |
@kbknapp :-) |
@kbknapp Sidenote: I could fix this for |
i.e. “no whitespace between them” as far as i’m concerned this is a bug since it’s very surprising, undocumented, divergent from how the usage string parser works, and subtle: if i wouldn’t have been lucky by already having a '-b' switch defined in another argument, it would have taken ages to find this. |
@flying-sheep Again. Limitation of the way macros actually work. Whitespace is not a matchable token. And the solution here might be (as I said to @kbknapp, is) to make the munching work with stages such that Sorry for the lack of documentation. I wrote this macro to ease the consumption of the builder pattern. I did not get around to documenting it for I will take an attempt to for As for being divergent from the usage string. The |
@flying-sheep Feel free to join How the rust macro system sees |
ah, makes sense. hmm, that’s problematic. so the fact that “-” isn’t a valid identifier character means that they are tokens. and e.g. |
@flying-sheep Indeed. The TT muncher that my macro uses to deconstruct the usage-string influenced format looks for these kinds of patterns. Macros can be tricky at times but when you get to know and use them like I do - they aren't all that difficult to write. If you're interested in learning more about macros. I recommend the following: https://danielkeep.github.io/tlborm/ (Feel free to skip past the technical introduction if it's too difficult and return to it later if you'd like to see how the macros actually work). |
is there any progress in 2.0? e.g. panicking if
|
And apparently one can also create an app like this: let matches = clap_app!(@app(App::new("freeform app-name ☺"))
(author: "...")
...
).get_matches(); |
I just hit this too. Is it not acceptable to add case to the macro that handles Edit: Alas, Rust doesn't allow Edit 2: (@arg ($arg:expr) $modes:tt --($long:expr) $($tail:tt)*) => {
clap_app!{ @arg ($arg.long($long)) $modes $($tail)* }
}; works. It allows |
This is implemented as |
There's a fix implemented for long arguments, sure, but subcommands (and the app name) still cannot have dashes it seems. Could we have a workaround for those too? Should I open a new issue? |
@g2p yeah please open a new issue so it gets more visibility than this older one 👍 |
the following code creates a
-b
/--group
option, not a-g
/--group-by
option.The text was updated successfully, but these errors were encountered: