Class: MCLI::Command::Option
- Inherits:
-
Object
- Object
- MCLI::Command::Option
- Defined in:
- lib/mcli/command/option.rb
Instance Attribute Summary collapse
-
#alias ⇒ Object
readonly
Returns the value of attribute alias.
-
#boolean ⇒ Object
readonly
Returns the value of attribute boolean.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(name, options = {}) ⇒ Option
constructor
A new instance of Option.
- #to_args ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ Option
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/mcli/command/option.rb', line 5 def initialize(name, ={}) opts = .merge() @name = name.to_sym @alias = opts[:alias].to_s if opts[:alias] @default = opts[:default] @required = opts[:required] @type = opts[:type] @boolean = opts[:boolean] end |
Instance Attribute Details
#alias ⇒ Object (readonly)
Returns the value of attribute alias.
3 4 5 |
# File 'lib/mcli/command/option.rb', line 3 def alias @alias end |
#boolean ⇒ Object (readonly)
Returns the value of attribute boolean.
3 4 5 |
# File 'lib/mcli/command/option.rb', line 3 def boolean @boolean end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
3 4 5 |
# File 'lib/mcli/command/option.rb', line 3 def default @default end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/mcli/command/option.rb', line 3 def name @name end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
3 4 5 |
# File 'lib/mcli/command/option.rb', line 3 def required @required end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/mcli/command/option.rb', line 3 def type @type end |
Instance Method Details
#to_args ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/mcli/command/option.rb', line 16 def to_args [].tap do |args| args << "-#{@alias}" if @alias args << "--#{@name} #{@name.upcase}" if @required && !@boolean args << "--#{@name} [#{@default || @name.upcase}]" if !@required && !@boolean args << "--[no-]#{@name}" if @boolean end end |