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, Provision, 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_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.
| 45 46 47 | # File 'lib/chef-cli/command/base.rb', line 45 def initialize super end | 
Instance Method Details
#check_license_acceptance ⇒ Object
| 82 83 84 85 | # File 'lib/chef-cli/command/base.rb', line 82 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
| 74 75 76 | # File 'lib/chef-cli/command/base.rb', line 74 def needs_help?(params) params.include?("-h") || params.include?("--help") end | 
#needs_version?(params) ⇒ Boolean
| 78 79 80 | # File 'lib/chef-cli/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-cli/command/base.rb', line 54 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 |