module

ArgParser

A powerful argument parser which uses a class or struct to define the arguments and their types.

Constants

QUOTE_CHARS = {'"' => '"', '“' => '”', '‘' => '’', '«' => '»', '‹' => '›', '❛' => '❜', '❝' => '❞', '❮' => '❯', '"' => '"'}

https://en.wikipedia.org/wiki/Quotation_mark#Summary_table

Constructors

new(args : Array(String))

Create a new {{@type}} from an array of arguments. See: https://github.com/watzon/arg_parser for more information.

Source

Class methods

tokenize(input : String)

Convert the string input into an array of tokens. Quoted values should be considered one token, but everything else should be split by spaces. Should work with all types of quotes, and handle nested quotes. Unmatched quotes should be considered part of the token.

Example:

input = %q{foo "bar baz" "qux \\"quux" "corge grault}
tokenize(input) # => ["foo", "bar baz", "qux \"quux", "\"corge", "grault"]
Source

Instance methods

_field_names
Source
_positional_args
Source
_validation_errors
Source
add_validation_error(key : String, errors : Array(String))
Source
on_conversion_error(key : String, value : String, type)

Called when a value cannot be converted to the expected type.

Note: You can override this method to change the way conversion errors are handled.

Source
on_missing_attribute(key : String)

Called when a required attribute is missing.

Note: You can override this method to change the way missing attributes are handled.

Source
on_unknown_attribute(key : String)

Called when an unknown attribute is found.

Note: You can override this method to change the way unknown attributes are handled.

Source
on_validation_error(key : String, value, errors : Array(String))

Called when a validation error occurs.

Note: You can override this method to change the way validation errors are handled.

Source
parse_key(arg : String) : String | Nil

Parse the argument key. Standard arg names start with a --. Aliases start with a single -`.

Arguments without a value become boolean true values.

Note: You can override this method to change the way keys are parsed.

Source

Nested types