module ArgParser

Overview

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

Defined in:

arg_parser.cr
arg_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

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(args : Array(String)) #

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


[View source]

Class Method Detail

def self.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"]

[View source]

Instance Method Detail

def _field_names : Array(String) #

[View source]
def _positional_args : Array(String) #

[View source]
def _validation_errors : Hash(String, Array(String)) #

[View source]
def add_validation_error(key : String, errors : Array(String)) #

[View source]
def 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.


[View source]
def 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.


[View source]
def 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.


[View source]
def 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.


[View source]
def 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.


[View source]