Class: Idcf::Cli::Service::Base
- Inherits:
-
Object
- Object
- Idcf::Cli::Service::Base
- Includes:
- Lib::Include::RecurringCalling
- Defined in:
- lib/idcf/cli/service/base.rb
Overview
model base
Direct Known Subclasses
Ilb::BaseServerForProtocol, Ilb::CheckJob, Ilb::SslalgorithmsIds
Constant Summary collapse
- ARG_TYPE_REQ =
:req
- ARG_TYPE_OPT =
:opt
- ARG_TYPE_REST =
:rest
- HELP_FORMAT =
{ ARG_TYPE_REQ => '<%<name>s>', ARG_TYPE_OPT => '[%<name>s]', ARG_TYPE_REST => '[%<name>s ...]' }.freeze
Class Attribute Summary collapse
-
.options ⇒ Object
readonly
Returns the value of attribute options.
Instance Attribute Summary collapse
-
#last_command ⇒ Object
readonly
Returns the value of attribute last_command.
-
#last_command_args ⇒ Object
readonly
Returns the value of attribute last_command_args.
Class Method Summary collapse
-
.description ⇒ Object
descritpion.
-
.make_param_s ⇒ Object
make param string.
-
.option(name, attr) ⇒ Object
option.
-
.reset ⇒ Object
reset setting reset.
- .valid_params ⇒ Object
Instance Method Summary collapse
-
#between_param?(arg_size) ⇒ Boolean
between params.
-
#cli_error(msg) ⇒ Object
cli error.
-
#do(_client, _o, *_args) ⇒ Object
do.
-
#initialize ⇒ Base
constructor
A new instance of Base.
-
#method_option_cnt(params) ⇒ Object
option count.
-
#method_rest?(params) ⇒ Boolean
is rest.
Methods included from Lib::Include::RecurringCalling
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
82 83 84 85 |
# File 'lib/idcf/cli/service/base.rb', line 82 def initialize @last_command = '' @last_command_args = [] end |
Class Attribute Details
.options ⇒ Object (readonly)
Returns the value of attribute options.
19 20 21 |
# File 'lib/idcf/cli/service/base.rb', line 19 def @options end |
Instance Attribute Details
#last_command ⇒ Object (readonly)
Returns the value of attribute last_command.
15 16 17 |
# File 'lib/idcf/cli/service/base.rb', line 15 def last_command @last_command end |
#last_command_args ⇒ Object (readonly)
Returns the value of attribute last_command_args.
15 16 17 |
# File 'lib/idcf/cli/service/base.rb', line 15 def last_command_args @last_command_args end |
Class Method Details
.description ⇒ Object
descritpion
42 43 44 |
# File 'lib/idcf/cli/service/base.rb', line 42 def description '' end |
.make_param_s ⇒ Object
make param string
49 50 51 52 53 54 55 56 57 |
# File 'lib/idcf/cli/service/base.rb', line 49 def make_param_s cp = [] valid_params.each do |param| f = HELP_FORMAT[param[0]] next if f.nil? cp << format(f, name: param[1]) end cp.join(' ') end |
.option(name, attr) ⇒ Object
option
34 35 36 37 |
# File 'lib/idcf/cli/service/base.rb', line 34 def option(name, attr) @options ||= {} @options[name] = attr end |
.reset ⇒ Object
reset setting reset
23 24 25 |
# File 'lib/idcf/cli/service/base.rb', line 23 def reset @options = {} end |
.valid_params ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/idcf/cli/service/base.rb', line 59 def valid_params [].tap do |result| new.method(:do).parameters.each do |param| result << param if target_param?(param[1]) end end end |
Instance Method Details
#between_param?(arg_size) ⇒ Boolean
between params
103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/idcf/cli/service/base.rb', line 103 def between_param?(arg_size) param = self.class.valid_params p_cnt = param.size return true if method_rest?(param) opt_cnt = method_option_cnt(param) min = p_cnt - opt_cnt msg = format('Argument: %<arg>s', arg: self.class.make_param_s) cli_error msg unless arg_size.between?(min, p_cnt) true end |
#cli_error(msg) ⇒ Object
cli error
150 151 152 |
# File 'lib/idcf/cli/service/base.rb', line 150 def cli_error(msg) raise Idcf::Cli::Error::CliError, msg end |
#do(_client, _o, *_args) ⇒ Object
do
94 95 96 |
# File 'lib/idcf/cli/service/base.rb', line 94 def do(_client, _o, *_args) cli_error 'Require override' end |
#method_option_cnt(params) ⇒ Object
option count
134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/idcf/cli/service/base.rb', line 134 def method_option_cnt(params) result = 0 return result if params.nil? params.each do |param| case param[0] when ARG_TYPE_OPT result += 1 end end result end |
#method_rest?(params) ⇒ Boolean
is rest
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/idcf/cli/service/base.rb', line 119 def method_rest?(params) return false if params.nil? params.each do |param| case param[0] when ARG_TYPE_REST return true end end false end |