Skip to content

Commit

Permalink
one more try
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinatorul committed Sep 3, 2015
1 parent a6e0e4b commit 4cda097
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ script:
after_success:
- |
travis-cargo --only stable doc-upload &&
travis-cargo --only stable coveralls
travis-cargo --only stable coveralls -- --features yaml
env:
global:
secure: JLBlgHY6OEmhJ8woewNJHmuBokTNUv7/WvLkJGV8xk0t6bXBwSU0jNloXwlH7FiQTc4TccX0PumPDD4MrMgxIAVFPmmmlQOCmdpYP4tqZJ8xo189E5zk8lKF5OyaVYCs5SMmFC3cxCsKjfwGIexNu3ck5Uhwe9jI0tqgkgM3URA=
45 changes: 45 additions & 0 deletions examples/17_yaml.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// In order to use YAML to define your CLI you must compile clap with the "yaml" feature becasue
// it's **not** included by default.
//
// In order to do this, ensure your Cargo.toml looks like one of the following:
//
// [dependencies.clap]
// features = ["yaml"]
//
// __OR__
//
// [dependencies]
// clap = { features = ["yaml"] }


// Using yaml requires calling a clap macro `load_yaml!()` so we must use the '#[macro_use]'
// directive
#[macro_use]
extern crate clap;

use clap::App;

fn main() {
// To load a yaml file containing our CLI definition such as the example '17_yaml.yml' we can
// use the convenience macro which loads the file at compile relative to the current file
// similiar to how modules are found.
//
// Then we pass that yaml object to App to build the CLI.
//
// Finally we call get_matches() to start the parsing process. We use the matches just as we
// normally would
let yml = load_yaml!("17_yaml.yml");
let m = App::from_yaml(yml).get_matches();

// Because the example 17_yaml.yml is rather large we'll just look a single arg so you can
// see that it works...
if let Some(mode) = m.value_of("mode") {
match mode {
"fast" => println!("We're really going now!"),
"slow" => println!("Awwww, too slow :("),
_ => unreachable!()
}
} else {
println!("--mode <MODE> wasn't used...");
}
}

0 comments on commit 4cda097

Please sign in to comment.