Skip to content

Commit 2d5354a

Browse files
committed
refactor(cli): Extract CLI style definitions
1 parent 7541cc7 commit 2d5354a

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ edition = "2021"
1616
license = "MIT OR Apache-2.0"
1717

1818
[workspace.dependencies]
19+
anstyle = "1.0.3"
1920
anyhow = "1.0.75"
2021
base64 = "0.21.3"
2122
bytesize = "1.3"
@@ -121,6 +122,7 @@ name = "cargo"
121122
path = "src/cargo/lib.rs"
122123

123124
[dependencies]
125+
anstyle.workspace = true
124126
anyhow.workspace = true
125127
base64.workspace = true
126128
bytesize.workspace = true

src/bin/cargo/cli.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use super::list_commands;
1414
use crate::command_prelude::*;
1515
use crate::util::is_rustup;
1616
use cargo::core::features::HIDDEN;
17+
use cargo::util::style;
1718

1819
pub fn main(config: &mut LazyConfig) -> CliResult {
1920
let args = cli().try_get_matches()?;
@@ -519,15 +520,14 @@ pub fn cli() -> Command {
519520
};
520521

521522
let styles = {
522-
use clap::builder::styling::*;
523-
Styles::styled()
524-
.header(AnsiColor::Green.on_default() | Effects::BOLD)
525-
.usage(AnsiColor::Green.on_default() | Effects::BOLD)
526-
.literal(AnsiColor::Cyan.on_default() | Effects::BOLD)
527-
.placeholder(AnsiColor::Cyan.on_default())
528-
.error(AnsiColor::Red.on_default() | Effects::BOLD)
529-
.valid(AnsiColor::Cyan.on_default() | Effects::BOLD)
530-
.invalid(AnsiColor::Yellow.on_default() | Effects::BOLD)
523+
clap::builder::styling::Styles::styled()
524+
.header(style::HEADER)
525+
.usage(style::USAGE)
526+
.literal(style::LITERAL)
527+
.placeholder(style::PLACEHOLDER)
528+
.error(style::ERROR)
529+
.valid(style::VALID)
530+
.invalid(style::INVALID)
531531
};
532532

533533
Command::new("cargo")

src/cargo/util/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ mod queue;
6060
pub mod restricted_names;
6161
pub mod rustc;
6262
mod semver_ext;
63+
pub mod style;
6364
pub mod to_semver;
6465
pub mod toml;
6566
pub mod toml_mut;

src/cargo/util/style.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use anstyle::*;
2+
3+
pub const HEADER: Style = AnsiColor::Green.on_default().effects(Effects::BOLD);
4+
pub const USAGE: Style = AnsiColor::Green.on_default().effects(Effects::BOLD);
5+
pub const LITERAL: Style = AnsiColor::Cyan.on_default().effects(Effects::BOLD);
6+
pub const PLACEHOLDER: Style = AnsiColor::Cyan.on_default();
7+
pub const ERROR: Style = AnsiColor::Red.on_default().effects(Effects::BOLD);
8+
pub const VALID: Style = AnsiColor::Cyan.on_default().effects(Effects::BOLD);
9+
pub const INVALID: Style = AnsiColor::Yellow.on_default().effects(Effects::BOLD);

0 commit comments

Comments
 (0)