Skip to content

Commit

Permalink
deps(cli-clap): bump up clap
Browse files Browse the repository at this point in the history
  • Loading branch information
SARDONYX-sard committed Aug 3, 2024
1 parent 3ff2034 commit 6953105
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 87 deletions.
181 changes: 96 additions & 85 deletions Cargo.lock

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

7 changes: 5 additions & 2 deletions dar2oar_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ path = "./src/main.rs"

[dependencies]
anyhow = { version = "1.0.86", features = ["backtrace"] }
# NOTE: clap uses v3.2.23, the last successfully built version, because color mode was erased in v4
clap = { version = "3.2.23", features = ["derive"] } # For CLI
clap = { version = "4.5.13", features = ["derive"] } # For CLI
dar2oar_core = { path = "../dar2oar_core", features = ["tracing"] }
tokio = { version = "1.37.0", features = [
"fs",
Expand All @@ -33,3 +32,7 @@ tracing-subscriber = "0.3.18"

[dev-dependencies]
pretty_assertions = "1.4.0"

[features]
default = ["color"]
color = []
36 changes: 36 additions & 0 deletions dar2oar_cli/src/cli/color.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use clap::builder::styling::{AnsiColor, Color, Style};

/// See: [`clap.rs not printing colors during --help`](https://stackoverflow.com/questions/74068168/clap-rs-not-printing-colors-during-help)
pub fn get_styles() -> clap::builder::Styles {
clap::builder::Styles::styled()
.usage(
Style::new()
.bold()
.underline()
.fg_color(Some(Color::Ansi(AnsiColor::Yellow))),
)
.header(
Style::new()
.bold()
.underline()
.fg_color(Some(Color::Ansi(AnsiColor::Yellow))),
)
.literal(Style::new().fg_color(Some(Color::Ansi(AnsiColor::Green))))
.invalid(
Style::new()
.bold()
.fg_color(Some(Color::Ansi(AnsiColor::Red))),
)
.error(
Style::new()
.bold()
.fg_color(Some(Color::Ansi(AnsiColor::Red))),
)
.valid(
Style::new()
.bold()
.underline()
.fg_color(Some(Color::Ansi(AnsiColor::Green))),
)
.placeholder(Style::new().fg_color(Some(Color::Ansi(AnsiColor::White))))
}
5 changes: 5 additions & 0 deletions dar2oar_cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
mod color;
mod commands;
mod convert;

use crate::cli::color::get_styles;
use crate::cli::commands::Commands;
use crate::init_tracing;
use convert::dar2oar;
Expand All @@ -11,6 +13,9 @@ use tracing::Level;
/// Converter CLI version
#[derive(Debug, clap::Parser)]
#[clap(name = "dar2oar", about)]
#[cfg_attr(feature = "color",
command(styles=get_styles())
)]
pub(crate) struct Cli {
#[clap(subcommand)]
command: Commands,
Expand Down

0 comments on commit 6953105

Please sign in to comment.