Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example from README seems to ignore config #27

Open
vi opened this issue Mar 17, 2021 · 1 comment
Open

Example from README seems to ignore config #27

vi opened this issue Mar 17, 2021 · 1 comment

Comments

@vi
Copy link

vi commented Mar 17, 2021

Running the example from README creates empty config.ini file (I expected it to contain options I specified on command line or default options). Trying to set, for example, timeout from config.ini fails.

If I add explicit conf(section), it reading that field from file starts working, but created config file is still empty.

README should be extended and include multiple launchers and example config file.

@marioortizmanero
Copy link
Owner

Hi! Sorry for the late reply.

Running the example from README creates empty config.ini file (I expected it to contain options I specified on command line or default options). Trying to set, for example, timeout from config.ini fails.

Now that you mention it I'm not exactly sure why config.ini is created when it's initialized if it's going to be empty anyway. The intended usage, which does write a different config file, is with write_file. This is a modified version of the showcase.rs example, after which a full config file will be created:

    let app = clap::App::new("demo");
    let mut conf = Config::parse(app, "config.ini").unwrap();
    conf.optional_field = Some(String::from("hola"));
    conf.write_file("config.ini").unwrap();
    println!("Parsed config: {:#?}", conf);

Perhaps the file could be created only when write_file is used? Anyhow, if you have this config file before running the example:

[Defaults]
timeout = 1000

The value for timeout is indeed 1000.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants