macro_rules! arg {
(-- $($long:ident)-+ | - $short:ident) => { ... };
(- $short:ident | -- $($long:ident)-+) => { ... };
(-- $($a:ident)-+) => { ... };
(- $a:ident) => { ... };
($a:literal) => { ... };
(+ $first:ident) => { ... };
(+ $first:ident - $($next:ident)-+) => { ... };
}
Expand description
Quick way to contruct Argument
s. Supports long and short arguments by
prepending one or two dashes, or “bare” arguments that aren’t classified as
either long or short.
Long arguments support anything Rust considers an “identifier” (variable
name), separated by at most one dash. For example arg!(--long)
or
arg!(--long-arg)
are valid, but arg!(--long--arg)
isn’t.
Short arguments must only be one character long (eg. arg!(-a)
). This
requirement isn’t checked due to limitations of macro_rules
, and I’m not
writing an entire proc macro crate for one shortcut.
If you use more than one character, it won’t ever be matched.
In a match block, you can “or” exactly one long and short argument like
arg!(-h | --help)
, which is equivalent to arg!(-h) | arg!(--help)
.
Bare arguments (anything not valid as a long or short) must be quoted, for
example arg!("bare-argument")
. Putting one or two dashes in front of the
argument will never match as it’d be recognized as a valid argument, but
three would be parsed as a bare (eg. arg!("---lol")
).
The arg!(+...)
syntax is used internally to combine Rust identifiers
separated by dashes.