Skip to content

Instantly share code, notes, and snippets.

@jaypei
Created September 1, 2016 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaypei/b43eb9d7bcda0d3f1dc550a0301f00c1 to your computer and use it in GitHub Desktop.
Save jaypei/b43eb9d7bcda0d3f1dc550a0301f00c1 to your computer and use it in GitHub Desktop.
clap_static_test
[package]
name = "clap_static_test"
version = "0.1.0"
authors = ["jaypei <jaypei97159@gmail.com>"]
[dependencies]
clap = {version = "2", features = ["yaml"]}
lazy_static = "0.2.1"
name: test
version: "0.1.0"
about: clap test
author: Jaypei <jaypei97159@gmail.com>
settings:
- ArgRequiredElseHelp
subcommands:
- a:
subcommands:
- b:
about: ab
args:
- port:
help: port number
index: 1
#[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