Skip to content

Commit b7ea2f3

Browse files
authored
feat(cargo-mono): colorize human output and improve publish failure excerpts (#306)
## Summary - add global `--color <auto|always|never>` for cargo-mono human output - add `CARGO_MONO_OUTPUT_COLOR` support and resolve precedence as: `--color` > env > `NO_COLOR` > auto - colorize human summary output across `list`, `changed`, `bump`, and `publish` while keeping JSON output unchanged - improve publish failure `details_excerpt` selection to prioritize actionable lines (`error:` -> `failed to ...` -> first non-empty) - update cargo-mono docs/contracts for color controls and output invariants ## Validation - `cargo fmt --all` - `cargo test`
1 parent fe72ea8 commit b7ea2f3

11 files changed

Lines changed: 534 additions & 40 deletions

File tree

crates/cargo-mono/src/cli.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{
55

66
use clap::{ArgAction, Args, Parser, Subcommand};
77

8-
use crate::types::{BumpLevel, OutputFormat};
8+
use crate::types::{BumpLevel, OutputColorMode, OutputFormat};
99

1010
#[derive(Debug, Parser)]
1111
#[command(
@@ -18,6 +18,9 @@ pub struct Cli {
1818
/// Output format for command results.
1919
#[arg(long, global = true, value_enum, default_value_t = OutputFormat::Human)]
2020
pub output: OutputFormat,
21+
/// Color mode for human output.
22+
#[arg(long, global = true, value_enum)]
23+
pub color: Option<OutputColorMode>,
2124

2225
#[command(subcommand)]
2326
pub command: Command,

crates/cargo-mono/src/commands/bump.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ use tracing::info;
66

77
use crate::{
88
cli::BumpArgs,
9-
commands::{print_output, targeting},
9+
commands::{print_output, targeting, OutputSettings},
1010
errors::Result,
1111
git,
12-
types::{BumpLevel, OutputFormat},
12+
types::BumpLevel,
1313
versioning, CargoMonoApp,
1414
};
1515

@@ -73,7 +73,7 @@ struct BumpResult {
7373
tags: Vec<String>,
7474
}
7575

76-
pub fn execute(args: &BumpArgs, output: OutputFormat, app: &CargoMonoApp) -> Result<i32> {
76+
pub fn execute(args: &BumpArgs, output: OutputSettings, app: &CargoMonoApp) -> Result<i32> {
7777
if args.level != BumpLevel::Prerelease && args.preid.is_some() {
7878
info!(
7979
command_path = "cargo-mono.bump",

crates/cargo-mono/src/commands/changed.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ use serde::Serialize;
22
use tracing::info;
33

44
use crate::{
5-
cli::ChangedArgs, commands::print_output, errors::Result, git, types::OutputFormat,
6-
CargoMonoApp,
5+
cli::ChangedArgs,
6+
commands::{print_output, OutputSettings},
7+
errors::Result,
8+
git, CargoMonoApp,
79
};
810

911
#[derive(Debug, Serialize)]
@@ -17,7 +19,7 @@ struct ChangedResult {
1719
packages: Vec<String>,
1820
}
1921

20-
pub fn execute(args: &ChangedArgs, output: OutputFormat, app: &CargoMonoApp) -> Result<i32> {
22+
pub fn execute(args: &ChangedArgs, output: OutputSettings, app: &CargoMonoApp) -> Result<i32> {
2123
let changed_files = git::changed_files(&args.base, args.include_uncommitted)?;
2224
let changed_packages = app
2325
.workspace

crates/cargo-mono/src/commands/list.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
use serde::Serialize;
22
use tracing::info;
33

4-
use crate::{commands::print_output, errors::Result, types::OutputFormat, CargoMonoApp};
4+
use crate::{
5+
commands::{print_output, OutputSettings},
6+
errors::Result,
7+
CargoMonoApp,
8+
};
59

610
#[derive(Debug, Serialize)]
711
struct ListPackage {
@@ -17,7 +21,7 @@ struct ListResult {
1721
packages: Vec<ListPackage>,
1822
}
1923

20-
pub fn execute(output: OutputFormat, app: &CargoMonoApp) -> Result<i32> {
24+
pub fn execute(output: OutputSettings, app: &CargoMonoApp) -> Result<i32> {
2125
let packages = app
2226
.workspace
2327
.packages()

0 commit comments

Comments
 (0)