Module: Idcf::Cli::Controller::Extend::Command

Defined in:
lib/idcf/cli/controller/extend/command.rb

Overview

command

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#public_commandsObject (readonly)

Returns the value of attribute public_commands.



10
11
12
# File 'lib/idcf/cli/controller/extend/command.rb', line 10

def public_commands
  @public_commands
end

Instance Method Details

#desc(usage, description, options = {}) ⇒ Object



53
54
55
56
57
58
# File 'lib/idcf/cli/controller/extend/command.rb', line 53

def desc(usage, description, options = {})
  super(usage, description, options)
  @public_commands ||= []
  cmd = usage.split(' ').shift
  @public_commands << cmd unless @public_commands.include?(cmd)
end

#register_method_option!(values) ⇒ Object

regist method option

Parameters:

  • values (Hash)

    name => desc



42
43
44
45
46
47
48
49
50
51
# File 'lib/idcf/cli/controller/extend/command.rb', line 42

def register_method_option!(values)
  return nil if values.nil?
  values.each do |opn, op|
    option = {}
    op.each do |ok, ov|
      option[ok.to_sym] = ov
    end
    method_option opn, option
  end
end

#register_module_method!(name, cls) ⇒ Object

register module mothod

Parameters:



31
32
33
34
35
36
37
# File 'lib/idcf/cli/controller/extend/command.rb', line 31

def register_module_method!(name, cls)
  register_method_option! cls.options
  desc "#{name} #{cls.make_param_s}", cls.description
  define_method name.to_sym do |*args|
    execute(__method__, *args)
  end
end

#register_schema_method_by_link!(link) ⇒ Object

register schema method by link

Parameters:

  • link (Idcf::JsonHyperSchema::Expands::LinkInfoBase)


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/idcf/cli/controller/extend/command.rb', line 15

def register_schema_method_by_link!(link)
  param_str   = Idcf::Cli::Lib::Api.command_param_str(link)
  method_desc = "#{link.title} #{param_str}"
  description = link.description
  desc method_desc.strip, description
  description = "#{description}\n\n#{Idcf::Cli::Lib::Document.make_document_desc(link)}"
  long_desc description
  define_method link.title.to_sym do |*args|
    execute(__method__, *args)
  end
end

#subcommand_structureObject



60
61
62
63
64
65
66
67
68
# File 'lib/idcf/cli/controller/extend/command.rb', line 60

def subcommand_structure
  result = super
  list = @public_commands
  list.concat(superclass.public_commands) if superclass.respond_to?(:public_commands)
  list.each do |cmd|
    result[cmd] = nil unless result.key?(cmd)
  end
  result
end