command_kit.rb icon indicating copy to clipboard operation
command_kit.rb copied to clipboard

Add a `CommandKit::Options::Type` base class

Open postmodern opened this issue 4 years ago • 0 comments

Add a CommandKit::Options::Type base class to make it easier to define custom OptionParser.accept types.

Example

class CustomType < CommandKit::Options::Type

  usage 'CUSTOM'
  
  pattern /.../
  
  def self.parse(value)
    # ...
  end
  
end

Options::Types.register CustomType

The register method would simply call OptionParser.accept and populate the USAGE Hash:

OptionParser.accept(type, type.pattern, &type.method(:parse))

postmodern avatar Jan 21 '22 04:01 postmodern