Class: Miniparse::Option

Inherits:
Command show all
Defined in:
lib/miniparse/command.rb

Overview

TODO FEATURE consider doing unambiguous matches for shortened options TODO FEATURE consider the option default value setting the type

Direct Known Subclasses

FlagOption, SwitchOption

Instance Attribute Summary collapse

Attributes inherited from Command

#desc, #name

Instance Method Summary collapse

Methods inherited from Command

#help_desc, #initialize, #run, spec_to_name, valid_spec

Constructor Details

This class inherits a constructor from Miniparse::Command

Instance Attribute Details

#shortableObject (readonly)

Returns the value of attribute shortable.



91
92
93
# File 'lib/miniparse/command.rb', line 91

def shortable
  @shortable
end

#valueObject (readonly)

Returns the value of attribute value.



91
92
93
# File 'lib/miniparse/command.rb', line 91

def value
  @value
end

Instance Method Details

#arg_to_value(arg) ⇒ Object

Raises:

  • (NotImplementedError)


97
98
99
# File 'lib/miniparse/command.rb', line 97

def arg_to_value(arg)
  raise NotImplementedError, "#{self.class} cannot respond to '#{__method__}'"
end

#check(arg) ⇒ Object



93
94
95
# File 'lib/miniparse/command.rb', line 93

def check(arg)
  arg_to_value(arg) != nil
end

#help_usageObject

Raises:

  • (NotImplementedError)


110
111
112
# File 'lib/miniparse/command.rb', line 110

def help_usage
  raise NotImplementedError, "#{self.class} cannot respond to '#{__method__}'"
end

#parse_value(arg) ⇒ Object



101
102
103
104
105
106
107
108
# File 'lib/miniparse/command.rb', line 101

def parse_value(arg)
  val = arg_to_value(arg)
  if val != nil
    @value = val
    run(val)
  end
  val
end