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

inspec detect learns human-readable output #720

Merged
merged 1 commit into from
May 9, 2016
Merged

Conversation

chris-rock
Copy link
Contributor

@chris-rock chris-rock commented May 6, 2016

This fixes #300

$ inspec detect 
Operating System Details
------------------------
Name: mac_os_x
Family: darwin
Release: 10.10.5
Arch: 

$ inspec detect --format json
{"name":"mac_os_x","family":"darwin","release":"10.10.5","arch":null}

@arlimus
Copy link
Contributor

arlimus commented May 8, 2016

Nice!! What do you think about:

diff --git a/lib/inspec/cli.rb b/lib/inspec/cli.rb
index 6ec254a..80ea5e1 100644
--- a/lib/inspec/cli.rb
+++ b/lib/inspec/cli.rb
@@ -115,9 +115,9 @@ class Inspec::InspecCLI < Inspec::BaseCLI # rubocop:disable Metrics/ClassLength
   target_options
   option :format, type: :string
   def detect
-    options_json[:command] = 'os.params'
     o = opts.dup
-    res = runner_command(opts, o[:command])
+    o[:command] = 'os.params'
+    res = run_command(o)
     if opts['format'] == 'json'
       puts res.to_json
     else
@@ -141,7 +141,7 @@ class Inspec::InspecCLI < Inspec::BaseCLI # rubocop:disable Metrics/ClassLength
       runner = Inspec::Runner.new(o)
       return Inspec::Shell.new(runner).start
     else
-      res = runner_command(opts, o[:command])
+      res = run_command(o)
       jres = res.respond_to?(:to_json) ? res.to_json : JSON.dump(res)
       puts jres
     end
@@ -156,10 +156,10 @@ class Inspec::InspecCLI < Inspec::BaseCLI # rubocop:disable Metrics/ClassLength

   private

-  def runner_command(opts, cmd)
+  def run_command(opts)
     opts[:test_collector] = 'mock'
     runner = Inspec::Runner.new(opts)
-    runner.create_context.load(cmd)
+    runner.create_context.load(opts[:command])
   end
 end

@chris-rock
Copy link
Contributor Author

Would you like to commit it or should I?

@arlimus
Copy link
Contributor

arlimus commented May 9, 2016

Pushed the update, thank you for the quick review!

@chris-rock chris-rock merged commit 20478ab into master May 9, 2016
@chris-rock chris-rock deleted the chris-rock/detect branch May 9, 2016 12:28
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.

Optimize InSpec detect
3 participants