Class: EverydayCliUtils::OptionList

Inherits:
Object
  • Object
show all
Defined in:
lib/everyday-cli-utils/option.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOptionList

Returns a new instance of OptionList.



146
147
148
149
150
151
# File 'lib/everyday-cli-utils/option.rb', line 146

def initialize
  @options          = {}
  @default_settings = {}
  @opts             = OptionParser.new
  @help_str         = nil
end

Instance Attribute Details

#default_settingsObject

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_strObject

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

#optsObject (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)
  @options[opt_name] = opt
end

#banner=(banner) ⇒ Object



183
184
185
# File 'lib/everyday-cli-utils/option.rb', line 183

def banner=(banner)
  @opts.banner = banner
end

#composite(*layers) ⇒ Object



169
170
171
172
173
# File 'lib/everyday-cli-utils/option.rb', line 169

def composite(*layers)
  hash = {}
  @options.each { |v| hash[v[0]] = v[1].composite(*layers) }
  hash
end

#helpObject



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, @options, 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)
  @options[opt_name].set(value) if @options.has_key?(opt_name)
end

#to_sObject



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)
  @options[opt_name].update(value, layer) if @options.has_key?(opt_name)
end