Class: Skytap::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/skytap/command_line.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Option

Returns a new instance of Option.



96
97
98
99
100
101
# File 'lib/skytap/command_line.rb', line 96

def initialize(name, options = {})
  @name = name.to_s
  @options = options.symbolize_keys
  @desc = @options[:desc]
  @default = @options[:default]
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



94
95
96
# File 'lib/skytap/command_line.rb', line 94

def default
  @default
end

#descObject (readonly)

Returns the value of attribute desc.



94
95
96
# File 'lib/skytap/command_line.rb', line 94

def desc
  @desc
end

#nameObject (readonly)

Returns the value of attribute name.



94
95
96
# File 'lib/skytap/command_line.rb', line 94

def name
  @name
end

Instance Method Details

#choicesObject



141
142
143
# File 'lib/skytap/command_line.rb', line 141

def choices
  @options[:in]
end

#negatable?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/skytap/command_line.rb', line 111

def negatable?
  switch? && @options[:negatable]
end

#show_default?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/skytap/command_line.rb', line 103

def show_default?
  !@options[:hide_default_value]
end

#signatureObject



132
133
134
135
136
137
138
139
# File 'lib/skytap/command_line.rb', line 132

def signature
  if switch?
    negation = '[no-]' if negatable?
    "--#{negation}#{name}"
  else
    "--#{name}=#{name.upcase}"
  end
end

#switch?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/skytap/command_line.rb', line 107

def switch?
  @options[:switch]
end

#valObject



115
116
117
118
119
120
121
# File 'lib/skytap/command_line.rb', line 115

def val
  if @set
    @val
  else
    default
  end
end

#val=(v) ⇒ Object



123
124
125
126
127
128
129
130
# File 'lib/skytap/command_line.rb', line 123

def val=(v)
  @set = true
  if switch?
    @val = !!v
  else
    @val = v
  end
end