Skip to main content

Module flags

Module flags 

Source
Available on crate feature cli only.
Expand description

The flags every CLI built on ctl-core shares, as Clap structs to flatten into a parser.

use clap::Parser;
use ctl_core::color::ColorMode;
use ctl_core::flags::OutputArgs;
use ctl_core::format::OutputFormat;

#[derive(Parser)]
struct Cli {
    #[command(flatten)]
    output: OutputArgs,
}

let cli = Cli::parse_from(["toy", "--format", "json", "--no-color"]);
assert_eq!(cli.output.format, OutputFormat::Json);
assert_eq!(cli.output.color(), ColorMode::Never);

Structs§

ColorLong
--color and --no-color without the -c short flag, for CLIs that already use -c for config.
DryRunArgs
-n/--dry-run, with --preview as a visible alias.
FlagWarning
One flag clash. Its Display text is the sentence a warning line holds after the {bin}: warning: prefix.
FormatArgs
-f/--format and -q/--quiet, with no colour flags.
FormatLong
--format and -q/--quiet without the -f short flag, for CLIs that already use -f for a domain flag such as --file.
OutputArgs
Output flags for the root parser: format, colour, and quiet. Flatten it with #[command(flatten)].

Enums§

FlagClash
The type of clash between flags that a FlagWarning reports. The last value still wins in every case.

Traits§

EnvPrefix
Binds each long option of a Command and of every subcommand to <PREFIX>_<LONG>, so the environment can set any flag a CLI declares.

Functions§

chassis_warnings
Find clashes among ctl-core’s shared flags in args.
emit_warnings
Print each warning to stderr as {bin}: warning: …, one per line.
env_under_flags
Removes each variable that the command line overrules, so the command line wins, and refuses two variables that conflict.
resolve_color
The colour mode in force: ColorMode::Never when no_color is set, otherwise color.
switch
The value of a --x/--no-x pair declared with Clap’s overrides_with both ways: on, the --x flag, returned unchanged.
warn_opposites
Find a --foo / --no-foo pair given together in args.