Class: Fuelcell::Parser::OptNameHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/fuelcell/parser/opt_name_handler.rb

Instance Method Summary collapse

Instance Method Details

#call(text) ⇒ Object

Parses the option defintiion name according to a set of rules that allows a short hand to be used to give the option name, its cli long & short names. The names are separated by |

specify all 3: <opt name>|<cli long>|<cli short>

when manually specifying all three the opt name is
always first
ex) version-opt|version|v

specify 2: <cli long>|<cli short>

<cli short>|<cli long>
<opt name>|<cli long>
when specifying 2 the opt name & cli long will be the same
if one of the given names is a cli short
ex) version|v
ex) v|version
ex) version-opt|version - only opt name and cli long are set

specify 1: <cli-long>

<cli-short>
ex) v       - cli short and opt name will be the same, no
              cli longs will be set
ex) version - cli long and opt name will be the same, no
              cli short will be set

Parameters:

  • name (String)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fuelcell/parser/opt_name_handler.rb', line 31

def call(text)
  text = text.to_s
  fail ArgumentError, 'option name can not be empty' if text.empty?

  parts = text.split('|')
  method_name = "manually_assign_#{parts.size}"
  name, long, short = send(method_name, parts)

  if !short.nil? && short.size > 1
    fail ArgumentError, "option short name (#{short}) can only be 1 char"
  end

  [name, long, short]
end