Skip to content

Commit

Permalink
Add comments to config file parsing
Browse files Browse the repository at this point in the history
Signed-off-by: David McNeil <mcneil.david2@gmail.com>
  • Loading branch information
davidMcneil committed Feb 7, 2020
1 parent 1523f84 commit 29d76ec
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion components/hab/src/cli.rs
Expand Up @@ -1314,10 +1314,18 @@ fn config_file_to_defaults(config_file: &str)

pub fn sub_sup_run(feature_flags: FeatureFlag) -> App<'static, 'static> {
let sub = if feature_flags.contains(FeatureFlag::CONFIG_FILE) {
// Construct a `clap::App` from the `structopt` decorated struct.
let mut sub = SubSupRun::clap();
if let Ok(config_file) = env::var("HAB_FEAT_CONFIG_FILE") {
// If we have a config file try and parse it as a `PartialSubSupRun`. `PartialSubSupRun`
// implements `ConfigOptDefaults` which allows it to set the default values of a
// `clap::App`.
match config_file_to_defaults(&config_file) {
Ok(defaults) => configopt::set_defaults(&mut sub, &defaults),
Ok(defaults) => {
// Set the defaults of the `clap::App` this is how config file values are
// interleaved with CLI specified arguments.
configopt::set_defaults(&mut sub, &defaults)
}
Err(e) => error!("Failed to parse config file, err: {}", e),
}
}
Expand Down

0 comments on commit 29d76ec

Please sign in to comment.