find_parameter

Function find_parameter 

Source
pub fn find_parameter(
    name: &str,
    args_os: impl IntoIterator<Item: Into<OsString>>,
) -> Option<OsString>
Expand description

In some cases, you may want to grab a config file path from CLI args before doing the main parse, so that you can load the config file content and pass it to conf::conf_builder(), if the config file path was present.

This helper function uses clap_lex to do that, which is already indirectly a dependency of conf anyways. It is only meant to be used for a one-off like this that is needed before the main parse.

See examples/serde/basic.rs for example usage.

Limitations:

  • Only returns the first example that it finds on the command line. Don’t use this with a multi option, only with a parameter.
  • No error reporting. If the parameter is found but has no argument, we just return None. That is expected to be caught in the Conf::parse step.
  • No auto-generated docs.

If you use this, you should add a dummy parameter of the same name to your top-level config struct, even if it is not used later in the program, so that you don’t get an “unexpected argument” error during the main parse, and so that this parameter will appear in the --help.