lib/chef-dk/command/base.rb in chef-dk-3.13.1 vs lib/chef-dk/command/base.rb in chef-dk-4.0.60

- old
+ new

@@ -17,16 +17,19 @@ require "mixlib/cli" require "chef-dk/helpers" require "chef-dk/version" require "chef/exceptions" +require "license_acceptance/acceptor" +require "license_acceptance/cli_flags/mixlib_cli" module ChefDK module Command class Base include Mixlib::CLI include ChefDK::Helpers + include LicenseAcceptance::CLIFlags::MixlibCLI option :help, short: "-h", long: "--help", description: "Show this message", @@ -45,18 +48,19 @@ # # optparser overwrites -h / --help options with its own. # In order to control this behavior, make sure the default options are # handled here. # - def run_with_default_options(params = [ ]) + def run_with_default_options(enforce_license, params = [ ]) if needs_help?(params) msg(opt_parser.to_s) 0 elsif needs_version?(params) msg("Chef Development Kit Version: #{ChefDK::VERSION}") 0 else + check_license_acceptance if enforce_license run(params) end rescue Chef::Exceptions::ConfigurationError => e err("ERROR: #{e.message}\n") 1 @@ -70,9 +74,13 @@ params.include?("-h") || params.include?("--help") end def needs_version?(params) params.include?("-v") || params.include?("--version") + end + + def check_license_acceptance + LicenseAcceptance::Acceptor.check_and_persist!("chef-dk", ChefDK::VERSION.to_s) end end end end