Class: CLI::DSL::Switch
Direct Known Subclasses
Option
Instance Attribute Summary
Attributes inherited from Base
#name
Instance Method Summary
collapse
#description, #description?
Constructor Details
#initialize(name, options = {}) ⇒ Switch
Returns a new instance of Switch.
137
138
139
140
141
142
143
|
# File 'lib/cli/dsl.rb', line 137
def initialize(name, options = {})
super(name, options)
if short = options[:short]
raise ParserError::ShortNameNotSymbolError.new(self, short) if not short.is_a? Symbol
raise ParserError::ShortNameIsInvalidError.new(self, short) if short.to_s.length > 1
end
end
|
Instance Method Details
#has_short? ⇒ Boolean
147
148
149
|
# File 'lib/cli/dsl.rb', line 147
def has_short?
@options.member? :short
end
|
#short ⇒ Object
151
152
153
|
# File 'lib/cli/dsl.rb', line 151
def short
@options[:short]
end
|
#switch ⇒ Object
155
156
157
|
# File 'lib/cli/dsl.rb', line 155
def switch
'--' + name.to_s.tr('_', '-')
end
|
#switch_short ⇒ Object
159
160
161
|
# File 'lib/cli/dsl.rb', line 159
def switch_short
'-' + short.to_s
end
|
#to_s ⇒ Object
163
164
165
|
# File 'lib/cli/dsl.rb', line 163
def to_s
switch
end
|