diff --git a/Cargo.lock b/Cargo.lock index 9abcce6ac..b2928f460 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -836,6 +836,7 @@ dependencies = [ "anstyle", "clap_lex", "strsim", + "terminal_size", ] [[package]] @@ -5074,6 +5075,16 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "terminal_size" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45c6481c4829e4cc63825e62c49186a34538b7b2750b73b266581ffb612fb5ed" +dependencies = [ + "rustix 1.0.5", + "windows-sys 0.59.0", +] + [[package]] name = "testcontainers" version = "0.23.3" diff --git a/Cargo.toml b/Cargo.toml index 71a26331a..9751bcc76 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,7 @@ approx = "0.5.1" async-trait = "0.1" bit-set = "0.8" brotli = ">=5, <9" -clap = { version = "4", features = ["derive", "unstable-markdown"] } +clap = { version = "4", features = ["derive", "unstable-markdown", "wrap_help"] } criterion = { version = "0.5", features = ["async_futures", "async_tokio", "html_reports"] } ctor = "0.4.2" dashmap = { version = "6.1.0", features = ["serde", "inline", "rayon"] } diff --git a/martin/src/args/root.rs b/martin/src/args/root.rs index 1cac7a862..6364e5c93 100644 --- a/martin/src/args/root.rs +++ b/martin/src/args/root.rs @@ -1,6 +1,9 @@ use std::path::PathBuf; -use clap::Parser; +use clap::{ + Parser, + builder::{Styles, styling::AnsiColor}, +}; use log::warn; use crate::MartinError::ConfigAndConnectionsError; @@ -19,11 +22,19 @@ use crate::config::Config; ))] use crate::file_config::FileConfigEnum; +/// Defines the styles used for the CLI help output. +const HELP_STYLES: Styles = Styles::styled() + .header(AnsiColor::Blue.on_default().bold()) + .usage(AnsiColor::Blue.on_default().bold()) + .literal(AnsiColor::White.on_default()) + .placeholder(AnsiColor::Green.on_default()); + #[derive(Parser, Debug, PartialEq, Default)] #[command( about, version, - after_help = "Use RUST_LOG environment variable to control logging level, e.g. RUST_LOG=debug or RUST_LOG=martin=debug. See https://docs.rs/env_logger/latest/env_logger/index.html#enabling-logging for more information." + after_help = "Use RUST_LOG environment variable to control logging level, e.g. RUST_LOG=debug or RUST_LOG=martin=debug. See https://docs.rs/env_logger/latest/env_logger/index.html#enabling-logging for more information.", + styles = HELP_STYLES )] pub struct Args { #[command(flatten)] diff --git a/martin/src/bin/martin-cp.rs b/martin/src/bin/martin-cp.rs index 252783bb2..91b030758 100644 --- a/martin/src/bin/martin-cp.rs +++ b/martin/src/bin/martin-cp.rs @@ -7,7 +7,10 @@ use std::time::Duration; use actix_http::error::ParseError; use actix_http::test::TestRequest; use actix_web::http::header::{ACCEPT_ENCODING, AcceptEncoding, Header as _}; -use clap::Parser; +use clap::{ + Parser, + builder::{Styles, styling::AnsiColor}, +}; use futures::TryStreamExt; use futures::stream::{self, StreamExt}; use log::{debug, error, info, log_enabled}; @@ -34,12 +37,19 @@ const SAVE_EVERY: Duration = Duration::from_secs(60); const PROGRESS_REPORT_AFTER: u64 = 100; const PROGRESS_REPORT_EVERY: Duration = Duration::from_secs(2); const BATCH_SIZE: usize = 1000; +/// Defines the styles used for the CLI help output. +const HELP_STYLES: Styles = Styles::styled() + .header(AnsiColor::Blue.on_default().bold()) + .usage(AnsiColor::Blue.on_default().bold()) + .literal(AnsiColor::White.on_default()) + .placeholder(AnsiColor::Green.on_default()); #[derive(Parser, Debug, PartialEq, Default)] #[command( about = "A tool to bulk copy tiles from any Martin-supported sources into an mbtiles file", version, - after_help = "Use RUST_LOG environment variable to control logging level, e.g. RUST_LOG=debug or RUST_LOG=martin_cp=debug. See https://docs.rs/env_logger/latest/env_logger/index.html#enabling-logging for more information." + after_help = "Use RUST_LOG environment variable to control logging level, e.g. RUST_LOG=debug or RUST_LOG=martin_cp=debug. See https://docs.rs/env_logger/latest/env_logger/index.html#enabling-logging for more information.", + styles = HELP_STYLES )] pub struct CopierArgs { #[command(flatten)] diff --git a/mbtiles/src/bin/mbtiles.rs b/mbtiles/src/bin/mbtiles.rs index 85c2fc6f0..ee5e205e8 100644 --- a/mbtiles/src/bin/mbtiles.rs +++ b/mbtiles/src/bin/mbtiles.rs @@ -1,5 +1,6 @@ use std::path::{Path, PathBuf}; +use clap::builder::{Styles, styling::AnsiColor}; use clap::{Parser, Subcommand}; use log::error; use mbtiles::{ @@ -8,12 +9,20 @@ use mbtiles::{ }; use tilejson::Bounds; +/// Defines the styles used for the CLI help output. +const HELP_STYLES: Styles = Styles::styled() + .header(AnsiColor::Blue.on_default().bold()) + .usage(AnsiColor::Blue.on_default().bold()) + .literal(AnsiColor::White.on_default()) + .placeholder(AnsiColor::Green.on_default()); + #[derive(Parser, PartialEq, Debug)] #[command( version, name = "mbtiles", about = "A utility to work with .mbtiles file content", - after_help = "Use RUST_LOG environment variable to control logging level, e.g. RUST_LOG=debug or RUST_LOG=mbtiles=debug. See https://docs.rs/env_logger/latest/env_logger/index.html#enabling-logging for more information." + after_help = "Use RUST_LOG environment variable to control logging level, e.g. RUST_LOG=debug or RUST_LOG=mbtiles=debug. See https://docs.rs/env_logger/latest/env_logger/index.html#enabling-logging for more information.", + styles = HELP_STYLES )] pub struct Args { /// Display detailed information