Skip to content

Commit

Permalink
switch to colorchoice-clap crate for color handling
Browse files Browse the repository at this point in the history
it still breaks tests, i think it's an issue with how we handle the
`check-release` subcommand
  • Loading branch information
suaviloquence committed Apr 8, 2024
1 parent 46179f8 commit b21b96f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 29 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ rustc_version = "0.4.0"
rayon = "1.8.0"
anstyle = "1.0.6"
anstream = "0.6.13"
colorchoice-clap = "1.0.3"

[dev-dependencies]
assert_cmd = "2.0"
Expand Down
33 changes: 4 additions & 29 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ use std::path::PathBuf;
use cargo_semver_checks::{
GlobalConfig, PackageSelection, ReleaseType, Rustdoc, ScopeSelection, SemverQuery,
};
use clap::{builder::PossibleValue, Args, Parser, Subcommand, ValueEnum};
use clap::{Args, Parser, Subcommand};

fn main() {
human_panic::setup_panic!();

let Cargo::SemverChecks(args) = Cargo::parse();

if let Some(color_choice) = args.check_release.color_choice {
color_choice.0.write_global();
}
args.check_release.color_choice.write_global();

if args.bugreport {
use bugreport::{bugreport, collector::*, format::Markdown};
Expand Down Expand Up @@ -111,29 +109,6 @@ fn exit_on_error<T>(log_errors: bool, inner: impl Fn() -> anyhow::Result<T>) ->
}
}

/// helper enum to derive [`clap::ValueEnum`] on [`anstream::ColorChoice`]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub(crate) struct ColorChoice(pub(crate) anstream::ColorChoice);

impl ValueEnum for ColorChoice {
fn value_variants<'a>() -> &'a [Self] {
use anstream::ColorChoice::*;
&[Self(Always), Self(AlwaysAnsi), Self(Auto), Self(Never)]
}

fn to_possible_value(&self) -> Option<PossibleValue> {
use anstream::ColorChoice::*;
let name = match self.0 {
Always => "always",
AlwaysAnsi => "always-ansi",
Auto => "auto",
Never => "never",
};

Some(PossibleValue::new(name))
}
}

#[derive(Debug, Parser)]
#[command(name = "cargo")]
#[command(bin_name = "cargo")]
Expand Down Expand Up @@ -317,8 +292,8 @@ struct CheckRelease {
/// auto (based on whether output is a tty), and never
///
/// Default is auto (use colors if output is a TTY, otherwise don't use colors)
#[arg(value_enum, long = "color")]
color_choice: Option<ColorChoice>,
#[command(flatten)]
color_choice: colorchoice_clap::Color,
}

impl From<CheckRelease> for cargo_semver_checks::Check {
Expand Down

0 comments on commit b21b96f

Please sign in to comment.