Created
September 1, 2016 02:42
-
-
Save jaypei/b43eb9d7bcda0d3f1dc550a0301f00c1 to your computer and use it in GitHub Desktop.
clap_static_test
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
[package] | |
name = "clap_static_test" | |
version = "0.1.0" | |
authors = ["jaypei <[email protected]>"] | |
[dependencies] | |
clap = {version = "2", features = ["yaml"]} | |
lazy_static = "0.2.1" |
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
name: test | |
version: "0.1.0" | |
about: clap test | |
author: Jaypei <[email protected]> | |
settings: | |
- ArgRequiredElseHelp | |
subcommands: | |
- a: | |
subcommands: | |
- b: | |
about: ab | |
args: | |
- port: | |
help: port number | |
index: 1 |
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
#[macro_use] | |
extern crate clap; | |
#[macro_use] | |
extern crate lazy_static; | |
use clap::{App,ArgMatches}; | |
pub struct MyArgs<'a> { | |
args: ArgMatches<'a> | |
} | |
lazy_static! { | |
pub static ref MATCHES: MyArgs<'static> = { | |
let yaml = load_yaml!("global.yml"); | |
MyArgs { | |
args: App::from_yaml(yaml).get_matches() | |
} | |
}; | |
} | |
fn main() { | |
let ref matches = MATCHES.args; | |
println!("{}", matches.subcommand_name().unwrap()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment