Class: Toys::Definition::FlagSyntax

Inherits:
Object
  • Object
show all
Defined in:
lib/toys/definition/flag.rb

Overview

Representation of a single flag.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ FlagSyntax

Parse flag syntax

Parameters:

  • str (String)

    syntax.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/toys/definition/flag.rb', line 42

def initialize(str)
  case str
  when /^(-[\?\w])$/
    setup(str, [$1], $1, "-", nil, nil, nil, nil)
  when /^(-[\?\w])( ?)\[(\w+)\]$/
    setup(str, [$1], $1, "-", :value, :optional, $2, $3)
  when /^(-[\?\w])\[( )(\w+)\]$/
    setup(str, [$1], $1, "-", :value, :optional, $2, $3)
  when /^(-[\?\w])( ?)(\w+)$/
    setup(str, [$1], $1, "-", :value, :required, $2, $3)
  when /^--\[no-\](\w[\?\w-]*)$/
    setup(str, ["--#{$1}", "--no-#{$1}"], str, "--", :boolean, nil, nil, nil)
  when /^(--\w[\?\w-]*)$/
    setup(str, [$1], $1, "--", nil, nil, nil, nil)
  when /^(--\w[\?\w-]*)([= ])\[(\w+)\]$/
    setup(str, [$1], $1, "--", :value, :optional, $2, $3)
  when /^(--\w[\?\w-]*)\[([= ])(\w+)\]$/
    setup(str, [$1], $1, "--", :value, :optional, $2, $3)
  when /^(--\w[\?\w-]*)([= ])(\w+)$/
    setup(str, [$1], $1, "--", :value, :required, $2, $3)
  else
    raise ToolDefinitionError, "Illegal flag: #{str.inspect}"
  end
end

Instance Attribute Details

#canonical_strObject (readonly)

Returns the value of attribute canonical_str.



75
76
77
# File 'lib/toys/definition/flag.rb', line 75

def canonical_str
  @canonical_str
end

#flag_styleObject (readonly)

Returns the value of attribute flag_style.



70
71
72
# File 'lib/toys/definition/flag.rb', line 70

def flag_style
  @flag_style
end

#flag_typeObject (readonly)

Returns the value of attribute flag_type.



71
72
73
# File 'lib/toys/definition/flag.rb', line 71

def flag_type
  @flag_type
end

#flagsObject (readonly)

Returns the value of attribute flags.



68
69
70
# File 'lib/toys/definition/flag.rb', line 68

def flags
  @flags
end

#original_strObject (readonly)

Returns the value of attribute original_str.



67
68
69
# File 'lib/toys/definition/flag.rb', line 67

def original_str
  @original_str
end

#str_without_valueObject (readonly)

Returns the value of attribute str_without_value.



69
70
71
# File 'lib/toys/definition/flag.rb', line 69

def str_without_value
  @str_without_value
end

#value_delimObject (readonly)

Returns the value of attribute value_delim.



73
74
75
# File 'lib/toys/definition/flag.rb', line 73

def value_delim
  @value_delim
end

#value_labelObject (readonly)

Returns the value of attribute value_label.



74
75
76
# File 'lib/toys/definition/flag.rb', line 74

def value_label
  @value_label
end

#value_typeObject (readonly)

Returns the value of attribute value_type.



72
73
74
# File 'lib/toys/definition/flag.rb', line 72

def value_type
  @value_type
end