Class: GLI::CommandLineOption

Inherits:
CommandLineToken show all
Defined in:
lib/gli/command_line_option.rb

Overview

An option, not a command or argument, on the command line

Direct Known Subclasses

Flag, Switch

Instance Attribute Summary collapse

Attributes inherited from CommandLineToken

#aliases, #description, #long_description, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CommandLineToken

#<=>, #names_and_aliases

Constructor Details

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

Creates a new option

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
:default_value - the default value of this option


18
19
20
21
# File 'lib/gli/command_line_option.rb', line 18

def initialize(names,options = {})
  super(names,options[:desc],options[:long_desc])
  @default_value = options[:default_value]
end

Instance Attribute Details

#associated_commandObject

Command to which this option “belongs”, nil if it’s a global option



9
10
11
# File 'lib/gli/command_line_option.rb', line 9

def associated_command
  @associated_command
end

#default_valueObject

:nodoc:



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

def default_value
  @default_value
end

Class Method Details

.name_as_string(name, negatable = true) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/gli/command_line_option.rb', line 23

def self.name_as_string(name,negatable=true)
  string = name.to_s
  if string.length == 1 
    "-#{string}" 
  elsif negatable
    "--[no-]#{string}"
  else
    "--#{string}"
  end
end