mirror of
https://github.com/rust-lang/cargo
synced 2024-10-01 05:23:56 +00:00
refactor(cli): Extract CLI style definitions
This commit is contained in:
parent
7541cc7afd
commit
2d5354adc9
5
Cargo.lock
generated
5
Cargo.lock
generated
|
@ -60,9 +60,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "anstyle"
|
||||
version = "1.0.0"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41ed9a86bf92ae6580e0a31281f65a1b1d867c0cc68d5346e2ae128dddfa6a7d"
|
||||
checksum = "b84bf0a05bbb2a83e5eb6fa36bb6e87baa08193c35ff52bbf6b38d8af2890e46"
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-parse"
|
||||
|
@ -258,6 +258,7 @@ dependencies = [
|
|||
name = "cargo"
|
||||
version = "0.75.0"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"anyhow",
|
||||
"base64",
|
||||
"bytesize",
|
||||
|
|
|
@ -16,6 +16,7 @@ edition = "2021"
|
|||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[workspace.dependencies]
|
||||
anstyle = "1.0.3"
|
||||
anyhow = "1.0.75"
|
||||
base64 = "0.21.3"
|
||||
bytesize = "1.3"
|
||||
|
@ -121,6 +122,7 @@ name = "cargo"
|
|||
path = "src/cargo/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
anstyle.workspace = true
|
||||
anyhow.workspace = true
|
||||
base64.workspace = true
|
||||
bytesize.workspace = true
|
||||
|
|
|
@ -14,6 +14,7 @@ use super::list_commands;
|
|||
use crate::command_prelude::*;
|
||||
use crate::util::is_rustup;
|
||||
use cargo::core::features::HIDDEN;
|
||||
use cargo::util::style;
|
||||
|
||||
pub fn main(config: &mut LazyConfig) -> CliResult {
|
||||
let args = cli().try_get_matches()?;
|
||||
|
@ -519,15 +520,14 @@ pub fn cli() -> Command {
|
|||
};
|
||||
|
||||
let styles = {
|
||||
use clap::builder::styling::*;
|
||||
Styles::styled()
|
||||
.header(AnsiColor::Green.on_default() | Effects::BOLD)
|
||||
.usage(AnsiColor::Green.on_default() | Effects::BOLD)
|
||||
.literal(AnsiColor::Cyan.on_default() | Effects::BOLD)
|
||||
.placeholder(AnsiColor::Cyan.on_default())
|
||||
.error(AnsiColor::Red.on_default() | Effects::BOLD)
|
||||
.valid(AnsiColor::Cyan.on_default() | Effects::BOLD)
|
||||
.invalid(AnsiColor::Yellow.on_default() | Effects::BOLD)
|
||||
clap::builder::styling::Styles::styled()
|
||||
.header(style::HEADER)
|
||||
.usage(style::USAGE)
|
||||
.literal(style::LITERAL)
|
||||
.placeholder(style::PLACEHOLDER)
|
||||
.error(style::ERROR)
|
||||
.valid(style::VALID)
|
||||
.invalid(style::INVALID)
|
||||
};
|
||||
|
||||
Command::new("cargo")
|
||||
|
|
|
@ -60,6 +60,7 @@ mod queue;
|
|||
pub mod restricted_names;
|
||||
pub mod rustc;
|
||||
mod semver_ext;
|
||||
pub mod style;
|
||||
pub mod to_semver;
|
||||
pub mod toml;
|
||||
pub mod toml_mut;
|
||||
|
|
9
src/cargo/util/style.rs
Normal file
9
src/cargo/util/style.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
use anstyle::*;
|
||||
|
||||
pub const HEADER: Style = AnsiColor::Green.on_default().effects(Effects::BOLD);
|
||||
pub const USAGE: Style = AnsiColor::Green.on_default().effects(Effects::BOLD);
|
||||
pub const LITERAL: Style = AnsiColor::Cyan.on_default().effects(Effects::BOLD);
|
||||
pub const PLACEHOLDER: Style = AnsiColor::Cyan.on_default();
|
||||
pub const ERROR: Style = AnsiColor::Red.on_default().effects(Effects::BOLD);
|
||||
pub const VALID: Style = AnsiColor::Cyan.on_default().effects(Effects::BOLD);
|
||||
pub const INVALID: Style = AnsiColor::Yellow.on_default().effects(Effects::BOLD);
|
Loading…
Reference in a new issue