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

Add an expandconfig utility to add default values #178

Merged
merged 5 commits into from
Dec 3, 2018
Merged

Conversation

Elarnon
Copy link
Collaborator

@Elarnon Elarnon commented Dec 1, 2018

This patch adds an expandconfig binary which is able to load a
configuration file, and write it back (in either TOML or YAML format)
with the default values expanded. This is useful in a variety of
scenarios:

  • Check that a configuration file is valid with:

    expandconfig /path/to/config.toml

  • See default field values and structure with:

    expandconfig

  • See all available fields with (YAML displays fields with a default
    None value while TOML skips them):

    expandconfig -f yaml

@Elarnon Elarnon requested a review from ulysseB December 1, 2018 14:50
Copy link
Owner

@ulysseB ulysseB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just minor style comments/questions.

let args: Vec<String> = env::args().collect();
let program = args[0].clone();

let mut opts = Options::new();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is their a reason why you didn't use structopt as you did in treesize ? I found structop much nicer to write/read.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree :)

What happened here is that I initially just read from stdin / wrote to stdout without args, then reached for getopts to make it a bit nicer since it was already a dependency of telamon. I didn't want to add structopt/clap dependencies, which are somewhat heavy, just for such a simple utility with two options. That may be misguided, esp. if we want to use structopt/clap for other CLI utilities in the future; I'm fine with converting the code if you prefer.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I would prefer we use a single library for all CLI tools. And structopt/clap seems the nicest way to go.

Cargo.toml Show resolved Hide resolved
Elarnon and others added 2 commits December 3, 2018 12:55
This patch adds an `expandconfig` binary which is able to load a
configuration file, and write it back (in either TOML or YAML format)
with the default values expanded.  This is useful in a variety of
scenarios:

 - Check that a configuration file is valid with:

    expandconfig /path/to/config.toml

 - See default field values and structure with:

    expandconfig

 - See all available fields with (YAML displays fields with a default
   `None` value while TOML skips them):

    expandconfig -f yaml
@Elarnon
Copy link
Collaborator Author

Elarnon commented Dec 3, 2018

@ulysseB expandconfig now uses structopt. I'll try converting the argument parsing code in explorer/config to structopt in a separate PR when I have time.

@Elarnon Elarnon mentioned this pull request Dec 3, 2018
@ulysseB
Copy link
Owner

ulysseB commented Dec 3, 2018

Ok. Can I merge this ?


#[derive(Debug, Clone, PartialEq, Eq)]
struct ParseFormatError {
_priv: (),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need this field ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't need it; it's just to prevent creating the error from somewhere else, which is not actually very useful. I can remove it.

@Elarnon
Copy link
Collaborator Author

Elarnon commented Dec 3, 2018

bors r=ulysseB

bors bot added a commit that referenced this pull request Dec 3, 2018
178: Add an `expandconfig` utility to add default values r=ulysseB a=Elarnon

This patch adds an `expandconfig` binary which is able to load a
configuration file, and write it back (in either TOML or YAML format)
with the default values expanded.  This is useful in a variety of
scenarios:

 - Check that a configuration file is valid with:

    expandconfig /path/to/config.toml

 - See default field values and structure with:

    expandconfig

 - See all available fields with (YAML displays fields with a default
   `None` value while TOML skips them):

    expandconfig -f yaml

Co-authored-by: Basile Clement <basile@clement.pm>
Co-authored-by: Basile Clement <basile.clement@ens.fr>
Co-authored-by: Basile Clement <elarnon@users.noreply.github.com>
@bors
Copy link
Contributor

bors bot commented Dec 3, 2018

Build succeeded

@bors bors bot merged commit 29bcdc8 into master Dec 3, 2018
@bors bors bot deleted the Elarnon/expandconfig branch December 3, 2018 19:55
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

Successfully merging this pull request may close these issues.

2 participants