Class: Idcf::Cli::Controller::Base

Inherits:
Thor
  • Object
show all
Extended by:
Extend::Init
Includes:
Include::Init, Lib::Include::RecurringCalling
Defined in:
lib/idcf/cli/controller/base.rb

Overview

Controller Base

Direct Known Subclasses

Autoscale, Compute, Dns, Ilb, Your

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Extend::Util

#get_region, #make_schema_path, #service_version

Methods included from Extend::SearchModule

#make_model_name, #make_module_classes, #make_service_paths, #search_module_class

Methods included from Extend::Override

#description

Methods included from Lib::Include::RecurringCalling

#recurring_calling

Methods inherited from Thor

command_help_string, command_regist, description, error_exit, exit_on_failure?, module_path, sub_command_regist, subcommand_structure

Class Attribute Details

Returns the value of attribute links.



54
55
56
# File 'lib/idcf/cli/controller/base.rb', line 54

def links
  @links
end

Instance Attribute Details

#cmdObject (readonly)

Returns the value of attribute cmd.



47
48
49
# File 'lib/idcf/cli/controller/base.rb', line 47

def cmd
  @cmd
end

#code_confObject (readonly)

Returns the value of attribute code_conf.



47
48
49
# File 'lib/idcf/cli/controller/base.rb', line 47

def code_conf
  @code_conf
end

#configObject (readonly)

Returns the value of attribute config.



47
48
49
# File 'lib/idcf/cli/controller/base.rb', line 47

def config
  @config
end

#m_classesObject (readonly)

Returns the value of attribute m_classes.



47
48
49
# File 'lib/idcf/cli/controller/base.rb', line 47

def m_classes
  @m_classes
end

Class Method Details

.init(argv) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/idcf/cli/controller/base.rb', line 56

def init(argv)
  o       = Thor::Options.new(class_options).parse(argv)
  region  = get_region(o)
  version = service_version(o)
  Idcf::Cli::Lib::Document.init(region: region, version: version)

  register_schema_method(o)

  make_module_classes.each do |cn, c|
    register_module_method!(cn, c)
  end
end

.register_schema_method(o) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/idcf/cli/controller/base.rb', line 69

def register_schema_method(o)
  path = make_schema_path(o)

  unless File.exist?(path)
    raise Idcf::Cli::Error::CliError, 'Run the command `update`' if self_call?
    return nil
  end

  analyst = Idcf::JsonHyperSchema::Analyst.new
  @links  = analyst.load(path).links
  @links.each do |link|
    register_schema_method_by_link!(link)
  end
end

.self_call?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/idcf/cli/controller/base.rb', line 84

def self_call?
  ARGV.include?(name.underscore.split('/').pop)
end

.service_nameObject

service name

Returns:

  • String



91
92
93
# File 'lib/idcf/cli/controller/base.rb', line 91

def service_name
  name.underscore.split('/').last
end

.service_versions(region) ⇒ Array

service version list

Returns:

  • (Array)


98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/idcf/cli/controller/base.rb', line 98

def service_versions(region)
  [].tap do |result|
    sn = service_name
    Idcf::Cli::Lib::Configure.get_code_conf(sn).each do |k, v|
      v['region'].each_key do |reg|
        next unless region == reg
        result << k
        break
      end
    end
  end
end

Instance Method Details

#versionsObject



114
115
116
117
# File 'lib/idcf/cli/controller/base.rb', line 114

def versions
  list = self.class.service_versions(self.class.get_region(options))
  puts make_result_str(make_result_data(list, options), options)
end