Skip to main content

OutputFlags

Struct OutputFlags 

Source
pub struct OutputFlags { /* private fields */ }
Expand description

CLI flag configuration for output behavior

OutputFlags captures the --quiet, --verbose, and --json flags that the main!() macro adds to every Clawless application. After parsing, the flags are forwarded to the TerminalPresenter to control how events are rendered.

OutputFlags does not produce output itself. Commands use the core Output type to emit events; OutputFlags configures the presenter that renders them.

§Examples

use clawless_cli::output::OutputFlags;

let flags = OutputFlags::new(
    clawless_cli::output::Verbosity::Default,
    clawless_cli::output::OutputMode::Text,
);
assert_eq!(flags.verbosity(), clawless_cli::output::Verbosity::Default);
assert_eq!(flags.mode(), clawless_cli::output::OutputMode::Text);

Implementations§

Source§

impl OutputFlags

Source

pub fn new(verbosity: Verbosity, mode: OutputMode) -> Self

Creates a new OutputFlags with the given verbosity and mode

§Examples
use clawless_cli::output::{OutputFlags, OutputMode, Verbosity};

let flags = OutputFlags::new(Verbosity::Default, OutputMode::Text);
assert_eq!(flags.verbosity(), Verbosity::Default);
assert_eq!(flags.mode(), OutputMode::Text);
Source

pub fn verbosity(&self) -> Verbosity

Returns the verbosity level

§Examples
use clawless_cli::output::{OutputFlags, OutputMode, Verbosity};

let flags = OutputFlags::new(Verbosity::Verbose, OutputMode::Text);
assert_eq!(flags.verbosity(), Verbosity::Verbose);
Source

pub fn mode(&self) -> OutputMode

Returns the output mode

§Examples
use clawless_cli::output::{OutputFlags, OutputMode, Verbosity};

let flags = OutputFlags::new(Verbosity::Default, OutputMode::Json);
assert_eq!(flags.mode(), OutputMode::Json);
Source

pub fn augment_command(command: Command) -> Command

Attaches --quiet, --verbose, and --json as global flags to a clap::Command

The --quiet and --verbose flags conflict with each other. All three flags are global, meaning they can appear before or after the subcommand name.

This method is called by the main!() macro expansion. Command authors do not call it directly.

§Examples
let command = clap::Command::new("test");
let command = clawless_cli::output::OutputFlags::augment_command(command);
Source

pub fn from_arg_matches(matches: &ArgMatches) -> Self

Constructs an OutputFlags from parsed CLI flags

Reads the --quiet, --verbose, and --json flags from the given ArgMatches and returns an OutputFlags configured accordingly. The command must have been augmented with augment_command before parsing.

This method is called by the main!() macro expansion. Command authors do not call it directly.

§Examples
let command = clawless_cli::output::OutputFlags::augment_command(
    clap::Command::new("test"),
);
let matches = command.get_matches_from(vec!["test", "--quiet"]);
let flags = clawless_cli::output::OutputFlags::from_arg_matches(&matches);
assert_eq!(flags.verbosity(), clawless_cli::output::Verbosity::Quiet);

Trait Implementations§

Source§

impl Clone for OutputFlags

Source§

fn clone(&self) -> OutputFlags

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for OutputFlags

Source§

impl Debug for OutputFlags

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for OutputFlags

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for OutputFlags

Source§

impl PartialEq for OutputFlags

Source§

fn eq(&self, other: &OutputFlags) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for OutputFlags

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.