Class: ChefCLI::Command::Base
- Inherits:
-
Object
- Object
- ChefCLI::Command::Base
- Includes:
- Helpers, LicenseAcceptance::CLIFlags::MixlibCLI, Mixlib::CLI
- Defined in:
- lib/chef-cli/command/base.rb
Direct Known Subclasses
CleanPolicyCookbooks, CleanPolicyRevisions, DeletePolicy, DeletePolicyGroup, DescribeCookbook, Diff, Env, Exec, Export, GemForwarder, Generate, GeneratorCommands::Base, Install, Push, PushArchive, ShellInit, ShowPolicy, Undelete, Update
Instance Method Summary collapse
- #check_license_acceptance ⇒ Object
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #needs_help?(params) ⇒ Boolean
- #needs_version?(params) ⇒ Boolean
-
#run_with_default_options(enforce_license, params = [ ]) ⇒ Object
optparser overwrites -h / –help options with its own.
Methods included from Helpers
#err, #git_bin_dir, #git_windows_bin_dir, #msg, #omnibus_bin_dir, #omnibus_embedded_bin_dir, #omnibus_env, #omnibus_expand_path, #omnibus_install?, #omnibus_root, #package_home, #stderr, #stdout, #system_command, #usr_bin_path, #usr_bin_prefix
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
56 57 58 |
# File 'lib/chef-cli/command/base.rb', line 56 def initialize super end |
Instance Method Details
#check_license_acceptance ⇒ Object
93 94 95 96 |
# File 'lib/chef-cli/command/base.rb', line 93 def check_license_acceptance # TODO - is this the right version? LicenseAcceptance::Acceptor.check_and_persist!("chef-workstation", ChefCLI::VERSION.to_s) end |
#needs_help?(params) ⇒ Boolean
85 86 87 |
# File 'lib/chef-cli/command/base.rb', line 85 def needs_help?(params) params.include?("-h") || params.include?("--help") end |
#needs_version?(params) ⇒ Boolean
89 90 91 |
# File 'lib/chef-cli/command/base.rb', line 89 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.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/chef-cli/command/base.rb', line 65 def (enforce_license, params = [ ]) if needs_help?(params) msg(opt_parser.to_s) 0 elsif needs_version?(params) msg("#{ChefCLI::Dist::PRODUCT} version: #{ChefCLI::VERSION}") 0 else check_license_acceptance if enforce_license run(params) end rescue Chef::Exceptions::ConfigurationError => e err("ERROR: #{e.}\n") 1 rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e err("ERROR: #{e.}\n") msg(opt_parser) 1 end |