Class: ArgParser::Option

Inherits:
Argument show all
Defined in:
lib/argparser/option.rb

Instance Attribute Summary collapse

Attributes inherited from Argument

#count, #default, #help, #multiple, #required, #validate, #value

Instance Method Summary collapse

Methods inherited from Argument

#add_value, #initialize, #printed_help, #reset, #set_default, #to_s, #valid?, #value?

Methods included from Tools

#hash2vars, #to_hash

Constructor Details

This class inherits a constructor from ArgParser::Argument

Instance Attribute Details

#paramObject (readonly) Also known as: argument

These attrs are from the manifest that is applied through constructor



6
7
8
# File 'lib/argparser/option.rb', line 6

def param
  @param
end

Instance Method Details

#nameObject

Returns first name as a ‘default’ one when several names given



8
9
10
# File 'lib/argparser/option.rb', line 8

def name
  @name ||= names.first
end

#namesObject

Names of an option (short, long, etc.)



15
16
17
# File 'lib/argparser/option.rb', line 15

def names
  @names ||= [@name]
end

#synopsisObject



19
20
21
22
23
24
25
# File 'lib/argparser/option.rb', line 19

def synopsis
  s = names.map{|n| n.size == 1 ? "-#{n}" : "--#{n}"}.join(', ')
  s << " #{param}" if param
  s = "[#{s}]" if !required
  s << '...' if multiple
  s
end