Skip to content

Commit

Permalink
Auto merge of #356 - sru:optional-yaml-example, r=kbknapp
Browse files Browse the repository at this point in the history
examples(17_yaml): conditinonally compile 17_yaml example

`cargo test` automatically compiles (but not run) examples as well. So, `cargo test` without `--features yaml` flag aborts before running tests, which IMO quite unexpected.

On the other hand, those `#[cfg(...)]` may confuse users.
  • Loading branch information
homu committed Dec 9, 2015
2 parents 82f9845 + 575de08 commit f2e4159
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion examples/17_yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ extern crate clap;

use clap::App;

#[cfg(feature = "yaml")]
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
Expand All @@ -42,4 +43,11 @@ fn main() {
} else {
println!("--mode <MODE> wasn't used...");
}
}
}

#[cfg(not(feature = "yaml"))]
fn main() {
// As stated above, if clap is not compiled with the YAML feature, it is disabled.
println!("YAML feature is disabled.");
println!("Pass --features yaml to cargo when trying this example.");
}

0 comments on commit f2e4159

Please sign in to comment.