module

Shell::AutoComplete::Parser

Constants

BARE_NUMBER_PATTERNS = { {"minus", false, false} => /\A-(\d+)\z/, {"minus", true, false} => /\A(-\d+)\z/, {"minus", false, true} => /\A-(\d+\D*)\z/, {"minus", true, true} => /\A(-\d+\D*)\z/, {"plus", false, false} => /\A\+(\d+)\z/, {"plus", true, false} => /\A(\+\d+)\z/, {"plus", false, true} => /\A\+(\d+\D*)\z/, {"plus", true, true} => /\A(\+\d+\D*)\z/, {"both", false, false} => /\A[-+](\d+)\z/, {"both", true, false} => /\A([-+]\d+)\z/, {"both", false, true} => /\A[-+](\d+\D*)\z/, {"both", true, true} => /\A([-+]\d+\D*)\z/}

The shapes a bare_number: flag accepts, keyed by {sign, keep_sign, suffix}. Built here once rather than per parse call. Capture group 1 is the value: keep_sign decides whether the sign travels with it (for a signed flag, where -20 means minus twenty rather than twenty), and suffix lets a unit or scale follow the digits (-123M).

Class methods

bare_number_pattern(sign : String, keep_sign : Bool, suffix : Bool) : Regex

Returns the pattern for a bare_number: configuration.

Source
parse_argv(argv : Array(String), specs : Array(FlagSpec), dash_positionals : Bool = false) : NamedTuple(values: Hash(String, Array(String | Nil)), positional: Array(String), occurrences: Array(Tuple(String, String | Nil)))

When dash_positionals is true, a single-dash token that matches no flag spec (e.g. -foo, or -x that isn't a short flag) is treated as a positional rather than raising "unknown flag". This lets add/remove positionals accept -name tokens alongside +name. Double-dash tokens (--name) are still parsed strictly as flags so typos and --help keep working; known flags always take precedence over a dash positional. Every matched flag occurrence is also recorded, in command-line order, as {spelling as typed, raw value consumed} — the spelling keeps its dashes and is not canonicalized, and the value is nil when none was consumed from argv (switches and forced-value shortcut flags).

A token is resolved in one order, and only that order: an exact spelling, then a pattern spec's shape, then a positional. So a declared flag is never shadowed by a bare_number: pattern, and a bare number is never swallowed by dash_positionals.

Source

Nested types