Allow end of options during Thor array parsing (#3547)

Signed-off-by: Jared Quick <jquick@chef.io>
This commit is contained in:
Jared Quick 2018-10-30 06:32:16 -04:00 committed by GitHub
parent b7b9581202
commit 0f42b31016
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 7 deletions

View file

@ -15,35 +15,41 @@ You can specify one or more reporters using the `--reporter` cli flag. You can a
Output json to screen.
```bash
inspec exec --reporter json
inspec exec example_profile --reporter json
or
inspec exec --reporter json:-
inspec exec example_profile --reporter json:-
```
Output yaml to screen
```bash
inspec exec --reporter yaml
inspec exec example_profile --reporter yaml
or
inspec exec --reporter yaml:-
inspec exec example_profile --reporter yaml:-
```
Output cli to screen and write json to a file.
```bash
inspec exec --reporter cli json:/tmp/output.json
inspec exec example_profile --reporter cli json:/tmp/output.json
```
Output nothing to screen and write junit and html to a file.
```bash
inspec exec --reporter junit:/tmp/junit.xml html:www/index.html
inspec exec example_profile --reporter junit:/tmp/junit.xml html:www/index.html
```
Output json to screen and write to a file. Write junit to a file.
```bash
inspec exec --reporter json junit:/tmp/junit.xml | tee out.json
inspec exec example_profile --reporter json junit:/tmp/junit.xml | tee out.json
```
If you wish to pass the profiles directly after specifying the reporters you will need to use the end of options flag `--`.
```bash
inspec exec --reporter json junit:/tmp/junit.xml -- profile1 profile2
```
If you are using the cli option `--json-config` you can also set reporters.

View file

@ -6,6 +6,20 @@ require 'thor'
require 'inspec/log'
require 'inspec/profile_vendor'
# Allow end of options during array type parsing
# https://github.com/erikhuda/thor/issues/631
class Thor::Arguments
def parse_array(_name)
return shift if peek.is_a?(Array)
array = []
while current_is_value?
break unless @parsing_options
array << shift
end
array
end
end
module Inspec
class BaseCLI < Thor
class << self

View file

@ -28,6 +28,16 @@ describe 'inspec exec with json formatter' do
JSON::Schema.validate(data, schema)
end
it 'can execute a simple file while using end of options after reporter cli option' do
out = inspec('exec --no-create-lockfile --reporter json -- ' + example_control)
out.stderr.must_equal ''
out.exit_status.must_equal 0
data = JSON.parse(out.stdout)
sout = inspec('schema exec-json')
schema = JSON.parse(sout.stdout)
JSON::Schema.validate(data, schema)
end
it 'can execute a profile and validate the json schema with target_id' do
out = inspec('exec ' + example_profile + ' --reporter json --no-create-lockfile --target-id 1d3e399f-4d71-4863-ac54-84d437fbc444')
out.stderr.must_equal ''