Class: ChefDK::Command::Base

Inherits:
Object
  • Object
show all
Includes:
Helpers, LicenseAcceptance::CLIFlags::MixlibCLI, Mixlib::CLI
Defined in:
lib/chef-dk/command/base.rb

Instance Method Summary collapse

Methods included from Helpers

#chefdk_home, #err, #git_bin_dir, #git_windows_bin_dir, #msg, #omnibus_apps_dir, #omnibus_bin_dir, #omnibus_chefdk_location, #omnibus_embedded_bin_dir, #omnibus_env, #omnibus_install?, #omnibus_root, #stderr, #stdout, #system_command, #usr_bin_path, #usr_bin_prefix

Constructor Details

#initializeBase

Returns a new instance of Base.



45
46
47
# File 'lib/chef-dk/command/base.rb', line 45

def initialize
  super
end

Instance Method Details

#check_license_acceptanceObject



82
83
84
# File 'lib/chef-dk/command/base.rb', line 82

def check_license_acceptance
  LicenseAcceptance::Acceptor.check_and_persist!("chef-dk", ChefDK::VERSION.to_s)
end

#needs_help?(params) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/chef-dk/command/base.rb', line 74

def needs_help?(params)
  params.include?("-h") || params.include?("--help")
end

#needs_version?(params) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/chef-dk/command/base.rb', line 78

def needs_version?(params)
  params.include?("-v") || params.include?("--version")
end

#run_with_default_options(enforce_license, params = [ ]) ⇒ Object

optparser overwrites -h / –help options with its own. In order to control this behavior, make sure the default options are handled here.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/chef-dk/command/base.rb', line 54

def run_with_default_options(enforce_license, params = [ ])
  if needs_help?(params)
    msg(opt_parser.to_s)
    0
  elsif needs_version?(params)
    msg("#{ChefDK::Dist::PRODUCT} 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
rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
  err("ERROR: #{e.message}\n")
  msg(opt_parser)
  1
end