Skip to content

Commit e43ea4f

Browse files
committed
feat(cli): Add colors to CLI help outputs
1 parent 5d8d2f9 commit e43ea4f

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ snafu = "0.8"
3838
[dependencies.clap]
3939
version = "4.5"
4040
optional = true
41-
features = ["derive", "wrap_help"]
41+
features = ["derive", "color", "wrap_help"]
4242

4343
[dependencies.git2]
4444
version = "0.20"

src/bin/git-warp-time.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use clap::CommandFactory;
55

6-
use git_warp_time::cli::Cli;
6+
use git_warp_time::cli::{Cli, STYLES};
77
use git_warp_time::FileSet;
88
use git_warp_time::{get_repo, reset_mtimes, resolve_repo_path};
99

@@ -40,7 +40,7 @@ type Result<T, E = Error> = std::result::Result<T, E>;
4040

4141
fn main() -> Result<()> {
4242
let version = option_env!("VERGEN_GIT_DESCRIBE").unwrap_or_else(|| env!("CARGO_PKG_VERSION"));
43-
let app = Cli::command().version(version);
43+
let app = Cli::command().version(version).styles(STYLES);
4444
let matches = app.get_matches();
4545
let positionals = matches.get_many::<String>("paths");
4646
let repo = get_repo().context(NoRepositorySnafu)?;

src/cli.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-FileCopyrightText: © 2021 Caleb Maclennan <caleb@alerque.com>
22
// SPDX-License-Identifier: GPL-3.0-only
33

4+
use clap::builder::styling::{AnsiColor, Styles};
45
use clap::Parser;
56

67
/// CLI utility that resets the timestamps of files in a Git repository working directory
@@ -28,3 +29,12 @@ pub struct Cli {
2829
#[arg(value_hint = clap::ValueHint::FilePath)]
2930
pub paths: Option<Vec<String>>,
3031
}
32+
33+
pub const STYLES: Styles = Styles::styled()
34+
.header(AnsiColor::Magenta.on_default().bold())
35+
.usage(AnsiColor::Yellow.on_default().bold())
36+
.literal(AnsiColor::BrightCyan.on_default().bold())
37+
.placeholder(AnsiColor::Cyan.on_default())
38+
.error(AnsiColor::BrightRed.on_default().bold())
39+
.valid(AnsiColor::BrightGreen.on_default().bold())
40+
.invalid(AnsiColor::BrightYellow.on_default().bold());

0 commit comments

Comments
 (0)