Class: EverydayCliUtils::OptionList
- Inherits:
-
Object
- Object
- EverydayCliUtils::OptionList
- Defined in:
- lib/everyday-cli-utils/option.rb
Instance Attribute Summary collapse
-
#default_settings ⇒ Object
Returns the value of attribute default_settings.
-
#help_str ⇒ Object
Returns the value of attribute help_str.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
- #[]=(opt_name, opt) ⇒ Object
- #banner=(banner) ⇒ Object
- #composite(*layers) ⇒ Object
- #help ⇒ Object
-
#initialize ⇒ OptionList
constructor
A new instance of OptionList.
- #parse!(argv = ARGV) ⇒ Object
- #register(type, opt_name, names, settings = {}, &block) ⇒ Object
- #set(opt_name, value) ⇒ Object
- #to_s ⇒ Object
- #update(opt_name, value, layer) ⇒ Object
Constructor Details
#initialize ⇒ OptionList
Returns a new instance of OptionList.
146 147 148 149 150 151 |
# File 'lib/everyday-cli-utils/option.rb', line 146 def initialize = {} @default_settings = {} @opts = OptionParser.new @help_str = nil end |
Instance Attribute Details
#default_settings ⇒ Object
Returns the value of attribute default_settings.
144 145 146 |
# File 'lib/everyday-cli-utils/option.rb', line 144 def default_settings @default_settings end |
#help_str ⇒ Object
Returns the value of attribute help_str.
144 145 146 |
# File 'lib/everyday-cli-utils/option.rb', line 144 def help_str @help_str end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
143 144 145 |
# File 'lib/everyday-cli-utils/option.rb', line 143 def opts @opts end |
Instance Method Details
#[]=(opt_name, opt) ⇒ Object
153 154 155 |
# File 'lib/everyday-cli-utils/option.rb', line 153 def []=(opt_name, opt) [opt_name] = opt end |
#banner=(banner) ⇒ Object
183 184 185 |
# File 'lib/everyday-cli-utils/option.rb', line 183 def () @opts. = end |
#composite(*layers) ⇒ Object
169 170 171 172 173 |
# File 'lib/everyday-cli-utils/option.rb', line 169 def composite(*layers) hash = {} .each { |v| hash[v[0]] = v[1].composite(*layers) } hash end |
#help ⇒ Object
175 176 177 |
# File 'lib/everyday-cli-utils/option.rb', line 175 def help @help_str.nil? ? @opts.help : @help_str end |
#parse!(argv = ARGV) ⇒ Object
187 188 189 |
# File 'lib/everyday-cli-utils/option.rb', line 187 def parse!(argv = ARGV) @opts.parse!(argv) end |
#register(type, opt_name, names, settings = {}, &block) ⇒ Object
165 166 167 |
# File 'lib/everyday-cli-utils/option.rb', line 165 def register(type, opt_name, names, settings = {}, &block) OptionDef.register(@opts, , type, opt_name, names, settings, @default_settings, &block) end |
#set(opt_name, value) ⇒ Object
157 158 159 |
# File 'lib/everyday-cli-utils/option.rb', line 157 def set(opt_name, value) [opt_name].set(value) if .has_key?(opt_name) end |
#to_s ⇒ Object
179 180 181 |
# File 'lib/everyday-cli-utils/option.rb', line 179 def to_s @help_str.nil? ? @opts.to_s : @help_str end |
#update(opt_name, value, layer) ⇒ Object
161 162 163 |
# File 'lib/everyday-cli-utils/option.rb', line 161 def update(opt_name, value, layer) [opt_name].update(value, layer) if .has_key?(opt_name) end |