From 80fe61b8cdfaea26f7167b4596a14a046751cfa7 Mon Sep 17 00:00:00 2001 From: Steven Danna Date: Tue, 23 Aug 2016 16:38:05 +0100 Subject: [PATCH 1/2] Expand relative paths based on profile location Also: Log to STDERR by default NB: This will result in absolute paths being rendered to lock files. We think that is OK for now since we are going to build some UX around path-based dependencies and lock files. Namely, we are going to tell people it is a bad idea. Signed-off-by: Steven Danna --- lib/inspec/cli.rb | 4 ++-- lib/inspec/dependencies/requirement.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/inspec/cli.rb b/lib/inspec/cli.rb index 7fe3f8de6..3a929dc1d 100644 --- a/lib/inspec/cli.rb +++ b/lib/inspec/cli.rb @@ -18,8 +18,8 @@ class Inspec::InspecCLI < Inspec::BaseCLI # rubocop:disable Metrics/ClassLength class_option :log_level, aliases: :l, type: :string, desc: 'Set the log level: info (default), debug, warn, error' - class_option :log_location, type: :string, default: STDOUT, - desc: 'Location to send diagnostic log messages to. (default: STDOUT)' + class_option :log_location, type: :string, default: STDERR, + desc: 'Location to send diagnostic log messages to. (default: STDERR)' class_option :diagnose, type: :boolean, desc: 'Show diagnostics (versions, configurations)' diff --git a/lib/inspec/dependencies/requirement.rb b/lib/inspec/dependencies/requirement.rb index a425ff43a..25b74c64d 100644 --- a/lib/inspec/dependencies/requirement.rb +++ b/lib/inspec/dependencies/requirement.rb @@ -91,7 +91,7 @@ module Inspec def source_url if opts[:path] - "file://#{opts[:path]}" + "file://#{File.expand_path(opts[:path], @cwd)}" elsif opts[:url] opts[:url] end From ed179ac088c227d3d51dbd568c02b52202ddb10e Mon Sep 17 00:00:00 2001 From: Steven Danna Date: Tue, 23 Aug 2016 17:00:23 +0100 Subject: [PATCH 2/2] Only redirect logging to STDERR if `format=json` Signed-off-by: Steven Danna --- lib/inspec/base_cli.rb | 10 +++++++++- lib/inspec/cli.rb | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/inspec/base_cli.rb b/lib/inspec/base_cli.rb index dcfaaee56..e3cdf1d43 100644 --- a/lib/inspec/base_cli.rb +++ b/lib/inspec/base_cli.rb @@ -134,7 +134,15 @@ module Inspec # logging singleton Inspec::Log. Eventually it would be nice to # move internal debug logging to use this logging singleton. # - Inspec::Log.init(o.log_location) + loc = if o.log_location + o.log_location + elsif %w{json json-min}.include?(o['format']) + STDERR + else + STDOUT + end + + Inspec::Log.init(loc) Inspec::Log.level = get_log_level(o.log_level) o[:logger] = Logger.new(STDOUT) diff --git a/lib/inspec/cli.rb b/lib/inspec/cli.rb index 3a929dc1d..69d20c115 100644 --- a/lib/inspec/cli.rb +++ b/lib/inspec/cli.rb @@ -18,8 +18,8 @@ class Inspec::InspecCLI < Inspec::BaseCLI # rubocop:disable Metrics/ClassLength class_option :log_level, aliases: :l, type: :string, desc: 'Set the log level: info (default), debug, warn, error' - class_option :log_location, type: :string, default: STDERR, - desc: 'Location to send diagnostic log messages to. (default: STDERR)' + class_option :log_location, type: :string, + desc: 'Location to send diagnostic log messages to. (default: STDOUT or STDERR)' class_option :diagnose, type: :boolean, desc: 'Show diagnostics (versions, configurations)'