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

read config from file/stdin #293

Merged
merged 2 commits into from
Dec 8, 2015
Merged

read config from file/stdin #293

merged 2 commits into from
Dec 8, 2015

Conversation

srenatus
Copy link
Contributor

@srenatus srenatus commented Dec 4, 2015

Fixes #292.

Removing the defaults was pragmatic:

  1. options['something'] is nil when the key isn't present anyways (and thus both default: nil and default: false are not necessary)
  2. If the defaults are there, they would override the options_json hash in the merge -- and we actually want the CLI parameters to take precedence.

An alternative might have been to declare an explicit "defaults" hashmap, but since the available configurables are supposed to come from train directly (in the future), this might not make too much sense now.

Shall I squash those commits?

@srenatus srenatus added Type: Bug Feature not working as expected Type: Enhancement Improves an existing feature labels Dec 7, 2015

def read_config(file)
if file == '-'
puts 'WARN: reading JSON config from standard input' if STDIN.tty?
Copy link
Contributor

Choose a reason for hiding this comment

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

what advantage do we get from printing a warning here? I'm just thinking about e.g. raw json output on stdout, where this might interfere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@arlimus when a user passes --json-config=-, she will just see that nothing happens. With this warning, the user will get an indication what is expected of her at the moment (i.e. provide JSON from the tty). It just affects the case of "reading from stdin when the session is interactive" (as opposed to non-interactive, i.e. cat config.json | inspec detect --json-config=-)

@arlimus
Copy link
Contributor

arlimus commented Dec 7, 2015

Awesome new functionality + diagnose helper!

pp options_json
puts 'Merged configuration:'
pp opts
end
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about an additional newline?

Here's a use-case where this might be clearer:

./bin/inspec detect --diagnose
InSpec version: 0.9.5
Train version: 0.9.1
Command line configuration:
{"diagnose"=>true}
JSON configuration file:
{}
Merged configuration:
{"diagnose"=>true}
{"name":null,"family":"arch","release":"4.2.5-1-ARCH","arch":null}

The last line feels like a part of diagnose.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or am I just using it wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it's fine. I'll add a newline.

@srenatus
Copy link
Contributor Author

srenatus commented Dec 7, 2015

I think I missed something with the reading from STDIN. please don't merge this yet ⚠️

@srenatus
Copy link
Contributor Author

srenatus commented Dec 7, 2015

@arlimus problem solved, ready to go now :)

@arlimus
Copy link
Contributor

arlimus commented Dec 7, 2015

Ah, didn't see that. Thanks @srenatus , that solves it!

@srenatus
Copy link
Contributor Author

srenatus commented Dec 7, 2015

As discussed, I'll give this one a touch-up. Please don't merge. ⚠️

srenatus and others added 2 commits December 7, 2015 16:10
Because of the way per-command arguments are handled, this is a little
different from the way e.g. kitchen handles it: any inspec command can
take the flag `--diagnose` to have it dump configuration first.

This add support for a JSON configuration file, where both

  inspec detect --json-config=config.json

and

  inspec detect --json-config=- <config.json

allow for reading the JSON config. There is no validation of its keys
in place.
@srenatus
Copy link
Contributor Author

srenatus commented Dec 7, 2015

ok, done :)

@chris-rock chris-rock added this to the 0.9.6 milestone Dec 7, 2015
@arlimus
Copy link
Contributor

arlimus commented Dec 8, 2015

👍 Thank you @srenatus !!

arlimus added a commit that referenced this pull request Dec 8, 2015
read config from file/stdin
@arlimus arlimus merged commit b1ec95e into master Dec 8, 2015
@arlimus arlimus deleted the sr/json-config branch December 8, 2015 10:32
@chris-rock chris-rock removed Type: Bug Feature not working as expected Type: Enhancement Improves an existing feature labels Dec 11, 2015
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.

None yet

3 participants