diff --git a/inspec-bin/bin/inspec b/inspec-bin/bin/inspec index 896b50e4f..c8c7ecaee 100755 --- a/inspec-bin/bin/inspec +++ b/inspec-bin/bin/inspec @@ -9,4 +9,4 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'inspec' require 'inspec/cli' -Inspec::InspecCLI.start(ARGV) +Inspec::InspecCLI.start(ARGV, enforce_license: true) diff --git a/lib/inspec/base_cli.rb b/lib/inspec/base_cli.rb index f164cee93..5aeb1cdca 100644 --- a/lib/inspec/base_cli.rb +++ b/lib/inspec/base_cli.rb @@ -23,6 +23,32 @@ module Inspec attr_accessor :inspec_cli_command end + def self.start(given_args = ARGV, config = {}) + check_license! if config[:enforce_license] || config[:enforce_license].nil? + + super(given_args, config) + end + + # EULA acceptance + def self.check_license! + allowed_commands = ['-h', '--help', 'help', '-v', '--version', 'version'] + + require 'license_acceptance/acceptor' + begin + if (allowed_commands & ARGV.map(&:downcase)).empty? && # Did they use a non-exempt command? + !ARGV.empty? # Did they supply at least one command? + LicenseAcceptance::Acceptor.check_and_persist( + 'inspec', + Inspec::VERSION, + logger: Inspec::Log, + ) + end + rescue LicenseAcceptance::LicenseNotAcceptedError + Inspec::Log.error 'InSpec cannot execute without accepting the license' + Inspec::UI.new.exit(:license_not_accepted) + end + end + # https://github.com/erikhuda/thor/issues/244 def self.exit_on_failure? true diff --git a/lib/inspec/cli.rb b/lib/inspec/cli.rb index cdee8b028..fbc9241d3 100644 --- a/lib/inspec/cli.rb +++ b/lib/inspec/cli.rb @@ -387,26 +387,6 @@ end #=====================================================================# help_commands = ['-h', '--help', 'help'] -version_commands = ['-v', '--version', 'version'] -commands_exempt_from_license_check = help_commands + version_commands - -#---------------------------------------------------------------------# -# EULA acceptance -#---------------------------------------------------------------------# -require 'license_acceptance/acceptor' -begin - if (commands_exempt_from_license_check & ARGV.map(&:downcase)).empty? && # Did they use a non-exempt command? - !ARGV.empty? # Did they supply at least one command? - LicenseAcceptance::Acceptor.check_and_persist( - 'inspec', - Inspec::VERSION, - logger: Inspec::Log, - ) - end -rescue LicenseAcceptance::LicenseNotAcceptedError - Inspec::Log.error 'InSpec cannot execute without accepting the license' - Inspec::UI.new.exit(:license_not_accepted) -end #---------------------------------------------------------------------# # Adjustments for help handling