From 436194793130f36e6deb8e53d5b3c924224e5fcb Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Wed, 21 May 2025 02:43:28 +0200 Subject: [PATCH 1/3] add autowrapping to the CLI --- Cargo.lock | 11 +++++++++++ Cargo.toml | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 1855f8995..9248808c8 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 e7027a518..8071ecdb5 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"] } From 537599ce21f6cbd4911848262f4ecafe33b82d87 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Wed, 21 May 2025 02:45:12 +0200 Subject: [PATCH 2/3] make sure that the CLIs have more color --- martin/src/args/root.rs | 14 ++++++++++++-- martin/src/bin/martin-cp.rs | 13 +++++++++++-- mbtiles/src/bin/mbtiles.rs | 10 +++++++++- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/martin/src/args/root.rs b/martin/src/args/root.rs index 1cac7a862..84a988458 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,18 @@ use crate::config::Config; ))] use crate::file_config::FileConfigEnum; +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 e0cd807cd..27e8401b0 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,18 @@ 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; +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..1729956de 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,19 @@ use mbtiles::{ }; use tilejson::Bounds; +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 From 6e0891993f5e3bc38921289fe87339da5b13fe58 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Wed, 21 May 2025 02:53:42 +0200 Subject: [PATCH 3/3] add a bit of the doc-helptext copilot asked --- martin/src/args/root.rs | 1 + martin/src/bin/martin-cp.rs | 1 + mbtiles/src/bin/mbtiles.rs | 1 + 3 files changed, 3 insertions(+) diff --git a/martin/src/args/root.rs b/martin/src/args/root.rs index 84a988458..6364e5c93 100644 --- a/martin/src/args/root.rs +++ b/martin/src/args/root.rs @@ -22,6 +22,7 @@ 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()) diff --git a/martin/src/bin/martin-cp.rs b/martin/src/bin/martin-cp.rs index 27e8401b0..a06ffafc3 100644 --- a/martin/src/bin/martin-cp.rs +++ b/martin/src/bin/martin-cp.rs @@ -37,6 +37,7 @@ 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()) diff --git a/mbtiles/src/bin/mbtiles.rs b/mbtiles/src/bin/mbtiles.rs index 1729956de..ee5e205e8 100644 --- a/mbtiles/src/bin/mbtiles.rs +++ b/mbtiles/src/bin/mbtiles.rs @@ -9,6 +9,7 @@ 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())