-
-
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
V3 master #510
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Example: ``` #[macro_use] extern crate clap; use clap::{App, SubCommand}; // Note lowercase variants, the subcommand will be exactly as typed here subcommands!{ enum MyProg { show, delete, make } } // Alternatively, if you wish to have variants which display // differently, or contain hyphens ("-") one can use this variation of // the macro subcommands!{ enum MyProgAlt { Show => "show", Delete => "delete", DoStuff => "do-stuff" } } fn main() { let m = App::new("myprog") .subcommand(SubCommand::with_name(MyProg::show)) .subcommand(SubCommand::with_name(MyProg::delete)) .subcommand(SubCommand::with_name(MyProg::make)) .get_matches_from(vec!["myprog", "show"]); match m.subcommand() { Some((MyProg::show, _)) => println!("'myprog show' was used"), Some((MyProg::delete, _)) => println!("'myprog delete' was used"), Some((MyProg::make, _)) => println!("'myprog make' was used"), None => println!("No subcommand was used"), } } ``` This has the benefit of giving non-exhaustive compile time errors when you add subcommands but forget to check or handle them later.
The v3 macros can now be used with multiple enums: ```rust args! { enum SubCmd1Args { One, Two, Three } enum SubCmd2Args { Four, Five, Six } } ```
The v3 macros can now be used with multiple enums: ```rust args! { enum SubCmd1Args { One, Two, Three } enum SubCmd2Args { Four, Five, Six } } ```
The args! macro now has the same alternate form as the subcommands! macro. ```rust args! { enum ProgArgs { Arg1 => "FILE", Arg2 => "Other" } } ```
r? @sru (yo-bot has picked a reviewer for you, use r? to override) |
☔ The latest upstream changes (presumably #517) made this pull request unmergeable. Please resolve the merge conflicts. |
A lot has changed, I'll reopen this when the time gets closer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Still a Work in Progress but getting closer and closer. It's now PR'able minus things like deprecation notices and updated readme/changelogs.
Before this is merged, current
master
will be branched off to becomev2-master
.Here's a list of things I still need to do
subcommands!
macro for using enums with subcommandsArgs::subcommand
Args::subcommand_name
Args::subcommand_matches
args!
macro for using enums with argsexamples/
with new subcommand args macrosarg!
subcommands!
_
->-
conversion