class

CommandParser

Inherits Reference < Object

The command parser is used to parse a command with parameters as follows:

  • All arguments are separated by spaces
  • Command can start with non-named arguments (positional) separated by spaces
  • First named argument means no more positional args
  • Names args are always K=V without spaces
  • Arguments can be quoted within '' or ""
  • Arguments can be arrays of values, within square brackets and separated by spaces.
  • No interpolation of values (for now?)

Constructors

new(query)
Source

Instance methods

arg_at(index)

Positional argument at index, raising exception if no such index

Source
arg_at?(index)

Positional argument at index, return nil if no such index

Source
arg_named(name)

Get the value of a named argument, raising exception if no such named argument

Source
arg_named?(name, default = nil)

Get the value of a named argument, return specified default value or nil if no such named argument

Source
bad_count

Number of positional args that occurred after the first named argument was found

Source
each_bad

Iterate thru the bad positional arguments

Source
each_named

Iterate through the named arguments

Source
expect?(*args, **params)

Use this to see if the command matches expected arguments and parameters, where values can be String (exact match), array of String (match one), Class expressions (type match), or any other "subsumption operator" matches (i.e. ===) include Regex expression. Example: `cmd.expect "/cmd", String, type: String?

Source
input
Source
missed

Portions of command we couldn't parse, or nil if none

Source
named_count

Number of named arguments

Source
positional_count

Number of positional arguments (up to the first named argument, if any)

Source