json

Shared output-mode (--json/--quiet/--raw) flags for command structs. Shared output-mode helpers for --json and --quiet flags.

struct Flags

source

pub struct Flags

Common output-mode flags that can be flattened into any command struct.

Field Type Description
json bool Emit output as JSON.
quiet bool Suppress normal output: print at most a bare ID, label or value, for scripts.
raw bool Emit script-friendly plain output (no themed styling).

Implements FromArgMatches, Args, Clone, Debug, Default.

Flags::print_delete

source

pub fn print_delete(&self, normal: impl FnOnce() -> String) -> Result<(), Error>

Print nothing (for delete in quiet mode), or the normal message.

Parameter Type Description
normal impl FnOnce() -> String builds the human-readable message, used unless --json or --quiet is set (also under --raw)
returns Result<(), Error> Always Ok(()).

Flags::print_envelope

source

pub fn print_envelope<T: Serialize>(
    &self,
    envelope: &Envelope<'_, T>,
    short_id: &str,
    normal: impl FnOnce() -> String,
) -> Result<(), Error>

Print a single entity wrapped in an Envelope. In JSON mode the envelope is serialized; in quiet mode only the short ID is printed; otherwise normal is called.

Parameter Type Description
envelope &Envelope<'_, T> the entity and its sidecars, serialized in JSON mode
short_id &str the ID printed in quiet mode
normal impl FnOnce() -> String builds the human-readable output, used unless --json or --quiet is set (also under --raw)
returns Result<(), Error> Ok(()) once the output is printed, or the JSON serialization error.

Flags::print_envelopes

source

pub fn print_envelopes<T: Serialize>(
    &self,
    envelopes: &[Envelope<'_, T>],
    raw: impl FnOnce() -> String,
    normal: impl FnOnce() -> String,
) -> Result<(), Error>

Print a list of envelopes. In JSON mode the list is serialized; in raw mode the raw callback renders script-friendly output; otherwise normal is used.

Parameter Type Description
envelopes &[Envelope<'_, T>] the entities and their sidecars, serialized as one array in JSON mode
raw impl FnOnce() -> String builds the script-friendly output for raw mode
normal impl FnOnce() -> String builds the human-readable output, used unless --json, --raw or --quiet is set
returns Result<(), Error> Ok(()) once the output is printed, or the JSON serialization error.

Flags::print_envelopes_with_short_ids

source

pub fn print_envelopes_with_short_ids<T: Serialize>(
    &self,
    envelopes: &[Envelope<'_, T>],
    short_ids: impl FnOnce() -> Vec<String>,
    normal: impl FnOnce() -> String,
) -> Result<(), Error>

Print a list of envelopes with quiet-mode short IDs. In JSON mode the envelopes are serialized; in quiet mode each short ID is printed on its own line; otherwise normal is called for the human-readable summary.

Parameter Type Description
envelopes &[Envelope<'_, T>] the entities and their sidecars, serialized as one array in JSON mode
short_ids impl FnOnce() -> Vec<String> builds the IDs printed in quiet mode
normal impl FnOnce() -> String builds the human-readable summary, used unless --json or --quiet is set (also under --raw)
returns Result<(), Error> Ok(()) once the output is printed, or the JSON serialization error.

Flags::print_entities

source

pub fn print_entities<T: Serialize>(
    &self,
    entities: &[T],
    short_ids: impl FnOnce() -> Vec<String>,
    normal: impl FnOnce() -> String,
) -> Result<(), Error>

Print a collection of entities. In JSON mode the slice is serialized; in quiet mode each short ID is printed on its own line; otherwise normal is called to produce the human-readable output.

Parameter Type Description
entities &[T] the entities, serialized as one array in JSON mode
short_ids impl FnOnce() -> Vec<String> builds the IDs printed in quiet mode
normal impl FnOnce() -> String builds the human-readable output, used unless --json or --quiet is set (also under --raw)
returns Result<(), Error> Ok(()) once the output is printed, or the JSON serialization error.

Flags::print_short_ids

source

pub fn print_short_ids<I, S>(
    &self,
    ids: I,
) -> Result<(), Error>
where
    I: IntoIterator<Item = S>,
    S: AsRef<str>

Print a list of short entity IDs, one per line.

This is the --quiet form of list-style commands: script-friendly output where each line is a single short ID that can be piped to another command.

Parameter Type Description
ids I the short IDs, in output order
returns Result<(), Error> Always Ok(()).

Flags::print_entity

source

pub fn print_entity<T: Serialize>(
    &self,
    entity: &T,
    short_id: &str,
    normal: impl FnOnce() -> String,
) -> Result<(), Error>

Print a single entity. In JSON mode the entity is serialized; in quiet mode only the short ID is printed; otherwise normal is called to produce the human-readable output.

Parameter Type Description
entity &T the entity, serialized in JSON mode
short_id &str the ID printed in quiet mode
normal impl FnOnce() -> String builds the human-readable output, used unless --json or --quiet is set (also under --raw)
returns Result<(), Error> Ok(()) once the output is printed, or the JSON serialization error.

Flags::print_raw_or

source

pub fn print_raw_or<T: Serialize>(
    &self,
    value: &T,
    raw: impl FnOnce() -> String,
    normal: impl FnOnce() -> String,
) -> Result<(), Error>

Print a value with explicit support for --raw.

Mode precedence: --json (serialized) > --raw (script-friendly plain text) > --quiet (nothing) > themed normal output.

Parameter Type Description
value &T the value, serialized in JSON mode
raw impl FnOnce() -> String builds the script-friendly output for raw mode
normal impl FnOnce() -> String builds the themed output for the default mode
returns Result<(), Error> Ok(()) once the output is printed, or the JSON serialization error.

Flags::render_raw_or

source

fn render_raw_or<T: Serialize>(
    &self,
    value: &T,
    raw: impl FnOnce() -> String,
    normal: impl FnOnce() -> String,
) -> Result<Option<String>, Error>

Internal: compute the chosen output for print_raw_or without printing.

Returns None for the silent (--quiet) branch so callers can suppress output. Exposed for unit testing the precedence rules.

Parameter Type Description
value &T the value, serialized in JSON mode
raw impl FnOnce() -> String builds the script-friendly output for raw mode
normal impl FnOnce() -> String builds the themed output for the default mode
returns Result<Option<String>, Error> The text to print, None in quiet mode, or the JSON serialization error.