Class: HammerCLI::Apipie::Command

Inherits:
HammerCLI::AbstractCommand show all
Includes:
Options, Resource, Messages
Defined in:
lib/hammer_cli/apipie/command.rb

Instance Attribute Summary

Attributes inherited from HammerCLI::AbstractCommand

#context

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Messages

#failure_message, #failure_message_for, #handle_exception, included, #success_message, #success_message_for

Methods included from Options

#get_option_value, #method_options, #method_options_for_params

Methods included from Resource

#action, #connection_options, included, #parent_command_resource, #resource, #resource_config

Methods inherited from HammerCLI::AbstractCommand

#adapter, add_option_details_section, add_option_schema, add_sets_help, autoload_subcommands, build_options, #clean_up_context, command_extensions, command_name, command_names, completion_map, completion_type_for, completion_types, define_simple_writer_for, #exception_handler, extend_help, extend_output_definition, extend_with, family_registry, find_options, help, help_extension_blocks, inherited_command_extensions, inherited_output_definition, #initialize, #interactive?, logger, option_builder, option_families, option_family, output, #output, #output_definition, output_definition, #parent_command, #parse, #run, use_option, validate_options, #validate_options, warning

Methods included from Subcommand

included

Constructor Details

This class inherits a constructor from HammerCLI::AbstractCommand

Class Method Details

.apipie_options(*args) ⇒ Object



29
30
31
# File 'lib/hammer_cli/apipie/command.rb', line 29

def self.apipie_options(*args)
  self.build_options(*args)
end

.create_option_builderObject



21
22
23
24
25
26
27
# File 'lib/hammer_cli/apipie/command.rb', line 21

def self.create_option_builder
  builder = super
  builder.builders += [
    OptionBuilder.new(resource, resource.action(action), :require_options => false)
  ] if resource_defined?
  builder
end

.desc(desc = nil) ⇒ Object



15
16
17
18
19
# File 'lib/hammer_cli/apipie/command.rb', line 15

def self.desc(desc=nil)
  super(desc) || resource.action(action).apidoc[:apis][0][:short_description] || " "
rescue
  " "
end

.option(switches, type, description, opts = {}, &block) ⇒ Object



84
85
86
87
88
89
90
91
92
93
# File 'lib/hammer_cli/apipie/command.rb', line 84

def self.option(switches, type, description, opts = {}, &block)
  option = HammerCLI::Apipie::OptionDefinition.new(switches, type, description, opts).tap do |option|
    declared_options << option
    block ||= option.default_conversion_block
    define_accessors_for(option, &block)
    add_option_schema(option) if option.value_formatter.is_a?(HammerCLI::Options::Normalizers::ListNested)
    completion_type_for(option, opts)
  end
  option
end

Instance Method Details

#executeObject



33
34
35
36
37
# File 'lib/hammer_cli/apipie/command.rb', line 33

def execute
  d = send_request
  print_data(d)
  return HammerCLI::EX_OK
end

#helpObject



39
40
41
42
43
44
45
# File 'lib/hammer_cli/apipie/command.rb', line 39

def help
  help_str = super
  if !resource || (!action.nil? && !resource.has_action?(action))
    help_str << "\n" + _("Unfortunately the server does not support such operation.") + "\n"
  end
  help_str
end