Expand description
Primitives to define parsers
Terminology
Flag
A simple no-argument command line option that takes no extra parameters, when decoded produces
a fixed value. Can have a short (-f
) or a long (--flag
) name, see Named::flag
and
Named::req_flag
. bpaf
parses flag into a fixed value known at a compile time.
For example --help
and -q
are long and short flags accepted by cargo
% cargo --help -q
Switch
A special case of a flag that gets decoded into a bool
, see Named::switch
.
It’s possible to represent flags --help
and -q
as booleans, true
for present and false
for absent.
% cargo --help -q
Argument
A command line option with a name that also takes a value. Can have a short (-f value
) or a
long (--flag value
) name, see Named::argument
.
For example rustc
takes a long argument --explain
with a value containing error code:
% rustc --explain E0571
Positional
A positional command with no additonal name, for example in vim main.rs
main.rs
is a positional argument. See positional
.
For example rustc
takes input as positional argument:
% rustc hello.rs
Command
A command defines a starting point for an independent subparser. See command
.
For example cargo
contains a command check
that accepts --workspace
switch.
% cargo check --workspace
Structs
A named thing used to create Flag, Switch or Argument.
Functions
Subcommand parser
A flag/switch/argument that has a long name
Positional argument that can be encoded as String
Positional argument that can be encoded as String and will be taken only if check passes
Positional argument in OS specific encoding
A flag/switch/argument that has a short name