Class: ChefCLI::Command::License
- Includes:
- ChefCLI::Configurable
- Defined in:
- lib/chef-cli/command/license.rb
Overview
This class will manage the license command in the chef-cli
Constant Summary collapse
- MAIN_COMMAND_HELP =
<<~HELP.freeze Usage: #{ChefCLI::Dist::EXEC} license [SUBCOMMAND] `#{ChefCLI::Dist::EXEC} license` command will validate the existing license or will help you interactively generate new free/trial license and activate the commercial license the chef team has sent you through email. HELP
- SUB_COMMANDS =
[ { name: "list", description: "List details of the license(s) installed on the system." }, { name: "add", description: "Create & install a Free/ Trial license or install a Commercial license on the system." }, ].freeze
Instance Attribute Summary collapse
-
#ui ⇒ Object
Returns the value of attribute ui.
Class Method Summary collapse
Instance Method Summary collapse
- #debug? ⇒ Boolean
-
#initialize ⇒ License
constructor
A new instance of License.
- #run(params) ⇒ Object
- #validate_params!(args) ⇒ Object
Methods included from ChefCLI::Configurable
#chef_config, #chefcli_config, #config_loader, #generator_config, #knife_config, #reset_config!
Methods inherited from Base
#check_license_acceptance, #needs_help?, #needs_version?, #run_with_default_options
Methods included from Helpers
#err, #fetch_chef_cli_version_pkg, #get_pkg_install_path, #get_pkg_prefix, #git_bin_dir, #git_windows_bin_dir, #habitat_chef_dke?, #habitat_env, #habitat_install?, #habitat_standalone?, #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
Instance Attribute Details
#ui ⇒ Object
Returns the value of attribute ui.
49 50 51 |
# File 'lib/chef-cli/command/license.rb', line 49 def ui @ui end |
Class Method Details
.banner ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/chef-cli/command/license.rb', line 51 def self. <<~BANNER #{MAIN_COMMAND_HELP} Subcommands: #{SUB_COMMANDS.map do |c| " #{c[:name].ljust(7)}#{c[:description]}" end.join("\n") } Options: BANNER end |
Instance Method Details
#debug? ⇒ Boolean
83 84 85 |
# File 'lib/chef-cli/command/license.rb', line 83 def debug? !!config[:debug] end |
#run(params) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/chef-cli/command/license.rb', line 69 def run(params) config_license_debug if debug? remaining_args = (params) return 1 unless validate_params!(remaining_args) if remaining_args.empty? ChefCLI::Licensing::Base.validate else ChefCLI::Licensing::Base.send(remaining_args[0]) end rescue ChefLicensing::LicenseKeyFetcher::LicenseKeyNotFetchedError ui.msg("License key not fetched. Please try again.") end |
#validate_params!(args) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/chef-cli/command/license.rb', line 87 def validate_params!(args) if args.length > 1 ui.err("Too many arguments") return false end valid_subcommands = SUB_COMMANDS.collect { |c| c[:name] } args.each do |arg| next if valid_subcommands.include?(arg) ui.err("Invalid option: #{arg}") return false end true end |