Class: GLI::Switch

Inherits:
CommandLineOption show all
Defined in:
lib/gli/switch.rb

Overview

Defines a command line switch

Instance Attribute Summary collapse

Attributes inherited from CommandLineOption

#associated_command

Attributes inherited from CommandLineToken

#aliases, #description, #long_description, #name

Instance Method Summary collapse

Methods inherited from CommandLineOption

name_as_string

Methods inherited from CommandLineToken

#<=>, #names_and_aliases

Constructor Details

#initialize(names, options = {}) ⇒ Switch

Creates a new switch

names - Array of symbols or strings representing the names of this switch options - hash of options:

:desc - the short description
:long_desc - the long description
:negatable - true or false if this switch is negatable; defaults to true
:default_value - default value if the switch is omitted


18
19
20
21
22
23
24
25
# File 'lib/gli/switch.rb', line 18

def initialize(names,options = {})
  super(names,options)
  @default_value = false if options[:default_value].nil?
  @negatable = options[:negatable].nil? ? true : options[:negatable]
  if @default_value != false && @negatable == false
    raise "A switch with default #{@default_value} that isn't negatable is useless"
  end
end

Instance Attribute Details

#default_valueObject

:nodoc:



7
8
9
# File 'lib/gli/switch.rb', line 7

def default_value
  @default_value
end

#negatableObject (readonly)

Returns the value of attribute negatable.



8
9
10
# File 'lib/gli/switch.rb', line 8

def negatable
  @negatable
end

Instance Method Details

#arguments_for_option_parserObject



27
28
29
# File 'lib/gli/switch.rb', line 27

def arguments_for_option_parser
  all_forms_a
end

#negatable?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/gli/switch.rb', line 31

def negatable?
  @negatable
end

#required?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/gli/switch.rb', line 35

def required?
  false
end