Cli

Struct Cli 

Source
pub struct Cli {
    pub command: Commands,
    pub root: Option<PathBuf>,
    pub log_level: LogLevel,
    pub format: OutputFormatArg,
    pub no_color: bool,
    pub config: Option<PathBuf>,
    pub quiet: bool,
    pub verbose: bool,
}
Expand description

Workspace Tools - Changeset-based version management.

This CLI provides comprehensive tools for managing Node.js workspaces using a changeset-based workflow. It supports both single-package and monorepo projects with independent or unified versioning strategies.

§Global Options

All global options apply to ALL subcommands and control behavior across the entire application:

  • --root: Changes working directory before executing commands
  • --log-level: Controls logging verbosity (stderr only)
  • --format: Controls output format (stdout only)
  • --no-color: Disables ANSI colors in output and logs
  • --config: Override default config file location

§Stream Separation

The CLI maintains strict separation between:

  • stderr: Logs only (controlled by --log-level)
  • stdout: Command output only (controlled by --format)

This ensures JSON output is never contaminated with logs, enabling reliable piping and parsing in scripts.

§Examples

# Initialize a new project
workspace init

# Add a changeset
workspace changeset add

# Preview version bump
workspace bump --dry-run

# JSON output with no logs (clean JSON for automation)
workspace --format json --log-level silent bump --dry-run

# Debug logging with text output
workspace --log-level debug changeset list

Fields§

§command: Commands

Subcommand to execute.

§root: Option<PathBuf>

Project root directory.

Changes working directory before executing the command. All file operations will be relative to this path.

Default: Current directory

§log_level: LogLevel

Logging level.

Controls verbosity of operation logs written to stderr. Does NOT affect command output (stdout).

Levels:

  • silent: No logs at all
  • error: Only critical errors
  • warn: Errors + warnings
  • info: General progress (default)
  • debug: Detailed operations
  • trace: Very verbose debugging

Default: info

§format: OutputFormatArg

Output format.

Controls format of command output written to stdout. Does NOT affect logging (stderr).

Formats:

  • human: Human-readable with colors and tables (default)
  • json: Pretty-printed JSON
  • json-compact: Compact JSON (single line)
  • quiet: Minimal output

Default: human

§no_color: bool

Disable colored output.

Removes ANSI color codes from both logs (stderr) and output (stdout). Also respects the NO_COLOR environment variable.

Useful for CI/CD environments and file redirection.

§config: Option<PathBuf>

Path to config file.

Override default config file location. Path can be relative or absolute.

Default: Auto-detect (.changesets.{toml,json,yaml,yml})

§quiet: bool

Quiet mode.

Minimizes both logs (stderr) and output (stdout). Equivalent to --log-level silent --format quiet.

Useful for scripts and automation where only exit code matters. Cannot be combined with –log-level, –format, or –verbose.

§verbose: bool

Verbose output mode.

Increases detail level in command output (stdout) and enables debug logs (stderr). Equivalent to --log-level debug.

Different from –log-level which only controls operational logs. Cannot be combined with –log-level or –quiet.

Implementations§

Source§

impl Cli

Source

pub const fn log_level(&self) -> LogLevel

Returns the raw log level from command line.

Note: Prefer effective_log_level() which accounts for –quiet and –verbose flags.

§Examples
use clap::Parser;
use sublime_cli_tools::cli::{Cli, LogLevel};

let cli = Cli::parse_from(["workspace", "--log-level", "debug", "version"]);
assert_eq!(cli.log_level(), LogLevel::Debug);
Source

pub const fn effective_log_level(&self) -> LogLevel

Returns the effective log level, accounting for –quiet and –verbose flags.

Priority:

  1. –quiet: Returns Silent
  2. –verbose: Returns Debug
  3. Otherwise: Returns the value from –log-level
§Examples
use clap::Parser;
use sublime_cli_tools::cli::{Cli, LogLevel};

// --quiet overrides to silent
let cli = Cli::parse_from(["workspace", "--quiet", "version"]);
assert_eq!(cli.effective_log_level(), LogLevel::Silent);

// --verbose sets debug level
let cli = Cli::parse_from(["workspace", "--verbose", "version"]);
assert_eq!(cli.effective_log_level(), LogLevel::Debug);

// Default uses --log-level value
let cli = Cli::parse_from(["workspace", "--log-level", "warn", "version"]);
assert_eq!(cli.effective_log_level(), LogLevel::Warn);
Source

pub const fn output_format(&self) -> OutputFormat

Returns the raw output format from command line.

Note: Prefer effective_output_format() which accounts for –quiet flag.

§Examples
use clap::Parser;
use sublime_cli_tools::cli::Cli;
use sublime_cli_tools::output::OutputFormat;

let cli = Cli::parse_from(["workspace", "--format", "json", "version"]);
assert_eq!(cli.output_format(), OutputFormat::Json);
Source

pub const fn effective_output_format(&self) -> OutputFormat

Returns the effective output format, accounting for –quiet flag.

Priority:

  1. –quiet: Returns Quiet
  2. Otherwise: Returns the value from –format
§Examples
use clap::Parser;
use sublime_cli_tools::cli::Cli;
use sublime_cli_tools::output::OutputFormat;

// --quiet overrides to quiet format
let cli = Cli::parse_from(["workspace", "--quiet", "version"]);
assert_eq!(cli.effective_output_format(), OutputFormat::Quiet);

// Default uses --format value
let cli = Cli::parse_from(["workspace", "--format", "json", "version"]);
assert_eq!(cli.effective_output_format(), OutputFormat::Json);
Source

pub fn is_color_disabled(&self) -> bool

Returns whether color output is disabled.

Also checks the NO_COLOR environment variable.

§Examples
use clap::Parser;
use sublime_cli_tools::cli::Cli;

let cli = Cli::parse_from(["workspace", "--no-color", "version"]);
assert!(cli.is_color_disabled());
Source

pub const fn root(&self) -> Option<&PathBuf>

Returns the root directory.

§Examples
use clap::Parser;
use sublime_cli_tools::cli::Cli;
use std::path::PathBuf;

let cli = Cli::parse_from(["workspace", "--root", "/tmp", "version"]);
assert_eq!(cli.root(), Some(&PathBuf::from("/tmp")));
Source

pub const fn config_path(&self) -> Option<&PathBuf>

Returns the config file path.

§Examples
use clap::Parser;
use sublime_cli_tools::cli::Cli;
use std::path::PathBuf;

let cli = Cli::parse_from(["workspace", "--config", "custom.toml", "version"]);
assert_eq!(cli.config_path(), Some(&PathBuf::from("custom.toml")));

Trait Implementations§

Source§

impl Args for Cli

Source§

fn group_id() -> Option<Id>

Report the ArgGroup::id for this set of arguments
Source§

fn augment_args<'b>(__clap_app: Command) -> Command

Append to Command so it can instantiate Self via FromArgMatches::from_arg_matches_mut Read more
Source§

fn augment_args_for_update<'b>(__clap_app: Command) -> Command

Append to Command so it can instantiate self via FromArgMatches::update_from_arg_matches_mut Read more
Source§

impl CommandFactory for Cli

Source§

fn command<'b>() -> Command

Build a Command that can instantiate Self. Read more
Source§

fn command_for_update<'b>() -> Command

Build a Command that can update self. Read more
Source§

impl Debug for Cli

Source§

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

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

impl FromArgMatches for Cli

Source§

fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>

Instantiate Self from ArgMatches, parsing the arguments as needed. Read more
Source§

fn from_arg_matches_mut( __clap_arg_matches: &mut ArgMatches, ) -> Result<Self, Error>

Instantiate Self from ArgMatches, parsing the arguments as needed. Read more
Source§

fn update_from_arg_matches( &mut self, __clap_arg_matches: &ArgMatches, ) -> Result<(), Error>

Assign values from ArgMatches to self.
Source§

fn update_from_arg_matches_mut( &mut self, __clap_arg_matches: &mut ArgMatches, ) -> Result<(), Error>

Assign values from ArgMatches to self.
Source§

impl Parser for Cli

Source§

fn parse() -> Self

Parse from std::env::args_os(), exit on error.
Source§

fn try_parse() -> Result<Self, Error>

Parse from std::env::args_os(), return Err on error.
Source§

fn parse_from<I, T>(itr: I) -> Self
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Parse from iterator, exit on error.
Source§

fn try_parse_from<I, T>(itr: I) -> Result<Self, Error>
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Parse from iterator, return Err on error.
Source§

fn update_from<I, T>(&mut self, itr: I)
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Update from iterator, exit on error. Read more
Source§

fn try_update_from<I, T>(&mut self, itr: I) -> Result<(), Error>
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Update from iterator, return Err on error.

Auto Trait Implementations§

§

impl Freeze for Cli

§

impl RefUnwindSafe for Cli

§

impl Send for Cli

§

impl Sync for Cli

§

impl Unpin for Cli

§

impl UnwindSafe for Cli

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

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

Source§

type Error = Infallible

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more