pub struct OutputConfig {
pub format: OutputFormat,
pub quiet: bool,
pub no_color: bool,
pub use_color: bool,
pub verbose: bool,
pub raw: bool,
pub no_interactive: bool,
}Expand description
Output configuration threaded through command handlers.
OutputConfig is intentionally a pure data carrier — no I/O handles, no
interior mutability. This keeps it Send + Sync + Clone, which is required
for the planned async/concurrent ApiClient (see project_async_requirement).
use_color is the resolved color decision after combining --color, the
NO_COLOR env var, and stderr’s TTY-ness. no_color is preserved as the
negation (!use_color) for source-compatibility with existing call sites
and tests that constructed OutputConfig { … } directly.
raw (from --raw) forces compact JSON (no pretty-printing) and strips
ANSI styling from text output. Useful for pipelines that line-buffer.
§Example
use xurl::cli::ColorChoice;
use xurl::output::{OutputConfig, OutputFormat};
let cfg = OutputConfig::new(OutputFormat::Json, false, false, ColorChoice::Never);
let mut buf: Vec<u8> = Vec::new();
let payload = serde_json::json!({ "status": "ok" });
cfg.print_response(&mut buf, &payload);
let rendered = String::from_utf8(buf).unwrap();
assert!(rendered.contains("\"status\""));Fields§
§format: OutputFormatResolved output format from --output / --json / --jsonl /
XURL_OUTPUT.
quiet: boolSuppress non-essential human chatter (--quiet / XURL_QUIET).
no_color: boolNegation of Self::use_color, kept for source compatibility with
call sites that pattern-match on the negative form.
use_color: boolResolved color decision after combining --color, NO_COLOR, and
stderr’s TTY-ness. The single source of truth for “should I emit
ANSI escapes”.
verbose: boolEnable verbose request/response logging
(--verbose / -v / XURL_VERBOSE).
raw: boolEmit unstyled, compact output (--raw / XURL_RAW). Strips ANSI in
text mode and forces compact JSON in machine modes.
no_interactive: boolSet when the user passed --no-interactive (or XURL_NO_INTERACTIVE).
Routed into OutputConfig so dialoguer-gating call sites can ask
Self::is_interactive_terminal without re-reading the parsed Cli
struct. Constructors default this to false; the runner sets it via
Self::with_no_interactive right after construction.
Implementations§
Source§impl OutputConfig
impl OutputConfig
Sourcepub fn new(
format: OutputFormat,
quiet: bool,
verbose: bool,
color: ColorChoice,
) -> Self
pub fn new( format: OutputFormat, quiet: bool, verbose: bool, color: ColorChoice, ) -> Self
Creates an OutputConfig from resolved CLI flags and environment.
use_color is computed from color together with NO_COLOR and
std::io::stderr().is_terminal():
NO_COLORis absolute (per https://no-color.org/): when set, color is disabled regardless of--color.--color alwaysoverrides the TTY check (still loses toNO_COLOR).--color neverdisables color unconditionally.--color autoenables color only when stderr is a TTY.
raw forces use_color = false and switches JSON output to compact
form (no pretty-printing).
Sourcepub fn new_with_raw(
format: OutputFormat,
quiet: bool,
verbose: bool,
color: ColorChoice,
raw: bool,
) -> Self
pub fn new_with_raw( format: OutputFormat, quiet: bool, verbose: bool, color: ColorChoice, raw: bool, ) -> Self
Like new, with an explicit raw flag.
Sourcepub fn with_no_interactive(self, no_interactive: bool) -> Self
pub fn with_no_interactive(self, no_interactive: bool) -> Self
Returns a copy of this config with the no_interactive field set.
Used by the runner immediately after construction to thread the parsed
--no-interactive (or XURL_NO_INTERACTIVE) flag into
Self::is_interactive_terminal.
Sourcepub fn is_interactive_terminal(&self) -> bool
pub fn is_interactive_terminal(&self) -> bool
Returns true when the active session can drive interactive prompts.
True only when:
--no-interactiveis NOT set,- stdin is a TTY,
- stderr is a TTY (dialoguer renders prompts on stderr).
Call sites that drive dialoguer::Select / dialoguer::Confirm
MUST gate on this — auto-engaging a prompt under a non-TTY session
leaves the dialoguer state machine waiting on /dev/null.
Sourcepub fn print_error_envelope(
&self,
err: &mut dyn Write,
reason: &str,
exit_code: i32,
message: &str,
)
pub fn print_error_envelope( &self, err: &mut dyn Write, reason: &str, exit_code: i32, message: &str, )
Emits a canonical error envelope with an explicit kebab-case reason.
Mirrors Self::print_error but lets the caller pin the reason
(e.g. "no-tty") rather than reading it from XurlError::kind().
Under text mode falls back to a plain “Error: …” line.
Sourcepub fn info(&self, err: &mut dyn Write, msg: &str)
pub fn info(&self, err: &mut dyn Write, msg: &str)
Prints an informational message (suppressed by –quiet or any
structured --output mode).
The runner passes a stderr writer here in the binary path; tests pass a Vec<u8>.
Sourcepub fn status(&self, err: &mut dyn Write, msg: &str)
pub fn status(&self, err: &mut dyn Write, msg: &str)
Prints a success/status message with optional color.
The runner passes a stderr writer here in the binary path; tests pass a Vec<u8>.
Sourcepub fn print_response(&self, out: &mut dyn Write, value: &Value)
pub fn print_response(&self, out: &mut dyn Write, value: &Value)
Prints an API response according to the configured output format.
I/O errors are intentionally swallowed (best-effort posture) so a
closed downstream pipe doesn’t abort the program — the SIGPIPE
restoration in main handles the more general case.
Under --raw, JSON output is emitted compactly (one line, no
whitespace) rather than pretty-printed.
Sourcepub fn print_stream_line(&self, out: &mut dyn Write, line: &str)
pub fn print_stream_line(&self, out: &mut dyn Write, line: &str)
Prints a streaming line according to the configured output format.
Sourcepub fn print_error(
&self,
err: &mut dyn Write,
error: &XurlError,
exit_code: i32,
)
pub fn print_error( &self, err: &mut dyn Write, error: &XurlError, exit_code: i32, )
Formats and prints an error to the supplied stderr writer.
Under any structured --output, emits the canonical envelope shape:
{"status":"error","reason":<kind>,"exit_code":<code>,"message":<display>}.
Json/Jsonl/Ndjson emit one JSON line; Yaml emits a YAML document; Csv/Tsv
emit a JSON line carrying the envelope (delimited formats are not a good
fit for nested error metadata).
Sourcepub fn print_success(&self, out: &mut dyn Write, payload: &Value)
pub fn print_success(&self, out: &mut dyn Write, payload: &Value)
Emits a canonical success envelope under structured modes.
Wraps payload (treated as a JSON object whose keys flatten in at
the top level) with {"status":"ok", ...payload}. Under text mode
the payload is passed through to Self::print_response so existing
formatters keep their shape.
Sourcepub fn print_dry_run(
&self,
out: &mut dyn Write,
would_succeed: bool,
exit_code: i32,
ctx: &Value,
)
pub fn print_dry_run( &self, out: &mut dyn Write, would_succeed: bool, exit_code: i32, ctx: &Value, )
Emits a canonical dry-run envelope under structured modes.
Shape: {"status":"dry_run","would_succeed":<bool>,"exit_code":<int>, ...ctx}.
Under text mode, falls back to a pass-through of ctx.
Sourcepub fn print_confirmation_required(
&self,
err: &mut dyn Write,
ctx: &Value,
exit_code: i32,
)
pub fn print_confirmation_required( &self, err: &mut dyn Write, ctx: &Value, exit_code: i32, )
Prints a canonical confirmation-required error envelope (U7).
Emitted when a destructive op was invoked under --no-interactive
without --force. ctx carries verb-context fields; the helper folds
status: "error", reason: "confirmation-required", and exit_code
into the same object on stderr.
Sourcepub fn verbose(&self, err: &mut dyn Write, msg: &str)
pub fn verbose(&self, err: &mut dyn Write, msg: &str)
Emits a verbose diagnostic line to err when verbose is on, quiet is
off, and the format is text.
Under --output json or --output jsonl, agents parsing structured
output must not encounter interleaved human text on stderr, so
verbose is suppressed (per the agent-native semantic-fields-over-
stderr-warnings principle). Mirrors the diag! macro pattern from the
bird CLI without the macro.
Sourcepub fn warning(&self, err: &mut dyn Write, msg: &str)
pub fn warning(&self, err: &mut dyn Write, msg: &str)
Emits a warning to err. Always goes to stderr in text mode; under
JSON modes the line is suppressed (the canonical envelope is the
channel for structured warnings — see plan U8’s deferred
warnings: [] envelope promotion).
Suppressed entirely under --quiet combined with JSON modes; under
--quiet text mode, warnings still surface (errors and warnings are
the load-bearing signals the operator must see).
Sourcepub fn progress(&self, err: &mut dyn Write, msg: &str)
pub fn progress(&self, err: &mut dyn Write, msg: &str)
Emits a progress / status line to err when the format is text and
stderr is a TTY. Quiet suppresses progress unconditionally.
Sourcepub fn print_message(&self, out: &mut dyn Write, msg: &str)
pub fn print_message(&self, out: &mut dyn Write, msg: &str)
Prints a simple text message (e.g. version, auth status) to the supplied writer. Respects –output json by wrapping in a JSON object.
Trait Implementations§
Source§impl Clone for OutputConfig
impl Clone for OutputConfig
Source§fn clone(&self) -> OutputConfig
fn clone(&self) -> OutputConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more