Expand description
Lexing: one command-line item at a time.
arg reads the next item: a long flag, one short letter, a word, or the
-- separator. It does not know which flags take a value, so it stops
where a value would start; the caller, which knows the flag, then calls
Arg::switch (no value) or Arg::value (read it). The derive, the
combinators and a hand-written dispatch! on flag
names all read items this way.
| command line | items |
|---|---|
--path=x | Long named path with value x |
--path x | Long named path, then Arg::value reads x |
-vpx | Short v, Short p, then Arg::value reads x |
-p=x | Short p, then Arg::value reads x |
- | Word - |
-- | Separator; every later word is a Word |
Structs§
- Long
Flag --nameor--name=value.- Short
Flag - One letter of
-abc. - Value
Options - How a flag takes a detached value, beyond the default of any word that is not flag-like.
- Word
- A word that is not a flag.
Enums§
Functions§
- arg
- Lex the next item. Backtracks at the end of the command line.
- arg_
plus argfor a command that also takes+options (set +e,declare +x): a word+abcis a bundle like-abc, its letters reported withShortFlag::plusset. A lone+is a word.- finish
- Succeed at the end of the command line; otherwise report what is left over.
- flag_
word - A flag-like word taken whole as a value, for
unknown_flags = "value": the last branch of analt, after every flag. Only a whole word: once a bundle has bound a letter, an unknown one after it is still an error. - is_
negative_ number - Whether
wordis a negative number:-then digits, at most one., and an optional exponent (eorE, an optional sign, at least one digit). Narrower than a float parse on purpose:-infand-NaNare likelier misspelled flags. - kind
- Classify the next item without consuming it; backtracks at the end of the
command line. Meant as a
dispatch!scrutinee, so a word is only offered to positional parsers and a flag only to flag parsers. - long_
only - GNU’s
getopt_long_only: a single-dash word whose name (up to the first=)is_longaccepts is a long option,-entry=mainas--entry=main, tried before the word is read as a bundle of short options.None, consuming nothing, for anything else, whichargthen lexes as usual. - number
- A negative number standing where a word starts, as a positional value: for a
positional declared
allow_negative_numbers, which would otherwise see a flag. - separator_
word --as a word, for a positional declareddouble_dash = "preserve": the separator is its value and flags go on being flags.- split
- The pieces of
valuebetweendelimiters; empty pieces are kept. - word
- A word that is not a flag: a positional value.