Class: HammerCLI::DefaultsCommand::AddDefaultsCommand

Inherits:
HammerCLI::DefaultsCommand show all
Defined in:
lib/hammer_cli/defaults_commands.rb

Instance Attribute Summary

Attributes inherited from AbstractCommand

#context

Instance Method Summary collapse

Methods inherited from HammerCLI::DefaultsCommand

#added_default_message, #bad_input, #defaults_not_supported_by_provider, #param_deleted, #provider_prob_message, #variable_not_found

Methods inherited from AbstractCommand

#adapter, add_option_details_section, add_option_schema, add_sets_help, build_options, #clean_up_context, command_extensions, #exception_handler, extend_help, extend_output_definition, extend_with, family_registry, help, #help, help_extension_blocks, inherited_command_extensions, #initialize, #interactive?, option, option_builder, option_families, option_family, output, #output, #output_definition, output_definition, #parent_command, #parse, #run, use_option, validate_options, #validate_options

Methods included from Subcommand

included

Constructor Details

This class inherits a constructor from HammerCLI::AbstractCommand

Instance Method Details

#executeObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/hammer_cli/defaults_commands.rb', line 107

def execute
  if option_provider.nil? && option_param_value.nil? || !option_provider.nil? && !option_param_value.nil?
    bad_input
    HammerCLI::EX_USAGE
  else
    if option_provider
      namespace = option_provider
      if !context[:defaults].providers.key?(namespace)
        provider_prob_message(namespace)
        return HammerCLI::EX_USAGE
      elsif !context[:defaults].providers[namespace].param_supported?(option_param_name.gsub('-','_'))
        defaults_not_supported_by_provider
        return HammerCLI::EX_CONFIG
      end
    end
    context[:defaults].add_defaults_to_conf({option_param_name => option_param_value}, namespace)
    added_default_message(option_param_name.to_s, option_param_value)
    HammerCLI::EX_OK
  end
rescue Defaults::DefaultsError, SystemCallError => e
  print_message(e.message)
  HammerCLI::EX_CONFIG
end