module ArgParser
Overview
A powerful argument parser which uses a class or struct to define the arguments and their types.
Defined in:
arg_parser.crarg_parser/annotations.cr
arg_parser/errors.cr
arg_parser/validator.cr
Constant Summary
-
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.
Class Method Summary
-
.tokenize(input : String)
Convert the string input into an array of tokens.
Instance Method Summary
- #_field_names : Array(String)
- #_positional_args : Array(String)
- #_validation_errors : Hash(String, Array(String))
- #add_validation_error(key : String, errors : Array(String))
-
#on_conversion_error(key : String, value : String, type)
Called when a value cannot be converted to the expected type.
-
#on_missing_attribute(key : String)
Called when a required attribute is missing.
-
#on_unknown_attribute(key : String)
Called when an unknown attribute is found.
-
#on_validation_error(key : String, value, errors : Array(String))
Called when a validation error occurs.
-
#parse_key(arg : String) : String | Nil
Parse the argument key.
Constructor Detail
Create a new {{@type}} from an array of arguments. See: https://github.com/watzon/arg_parser for more information.
Class Method Detail
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"]
Instance Method Detail
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.
Called when a required attribute is missing.
Note: You can override this method to change the way missing attributes are handled.
Called when an unknown attribute is found.
Note: You can override this method to change the way unknown attributes are handled.
Called when a validation error occurs.
Note: You can override this method to change the way validation errors are handled.
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.