Class: MCLI::Command::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/mcli/command/option.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options={})
  opts = default_options.merge(options)

  @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

#aliasObject (readonly)

Returns the value of attribute alias.



3
4
5
# File 'lib/mcli/command/option.rb', line 3

def alias
  @alias
end

#booleanObject (readonly)

Returns the value of attribute boolean.



3
4
5
# File 'lib/mcli/command/option.rb', line 3

def boolean
  @boolean
end

#defaultObject (readonly)

Returns the value of attribute default.



3
4
5
# File 'lib/mcli/command/option.rb', line 3

def default
  @default
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/mcli/command/option.rb', line 3

def name
  @name
end

#requiredObject (readonly)

Returns the value of attribute required.



3
4
5
# File 'lib/mcli/command/option.rb', line 3

def required
  @required
end

#typeObject (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_argsObject



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