From c4aee8846d124f9c70fac330ef1ff9acde7fee42 Mon Sep 17 00:00:00 2001 From: Ruben Arts Date: Tue, 11 Mar 2025 16:47:06 +0100 Subject: [PATCH] feat: improve cli help headers and styling (#3329) --- Cargo.lock | 11 --- Cargo.toml | 2 - crates/pixi_config/src/lib.rs | 16 ++--- crates/pixi_consts/src/consts.rs | 3 + docs/reference/cli/pixi.md | 6 +- docs/reference/cli/pixi/add.md | 4 -- docs/reference/cli/pixi/remove.md | 4 -- pixi_docs/Cargo.lock | 11 --- src/cli/cli_config.rs | 16 ++--- src/cli/config.rs | 6 +- src/cli/mod.rs | 107 ++++++++++++++++++++++-------- 11 files changed, 105 insertions(+), 81 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 62dd0e42d..4aec0304c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1178,16 +1178,6 @@ dependencies = [ "clap_derive", ] -[[package]] -name = "clap-verbosity-flag" -version = "3.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2678fade3b77aa3a8ff3aae87e9c008d3fb00473a41c71fbf74e91c8c7b37e84" -dependencies = [ - "clap", - "log", -] - [[package]] name = "clap_builder" version = "4.5.31" @@ -4305,7 +4295,6 @@ dependencies = [ "base64 0.22.1", "chrono", "clap", - "clap-verbosity-flag", "clap_complete", "clap_complete_nushell", "console", diff --git a/Cargo.toml b/Cargo.toml index 410623bb4..2b7d37ebc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,6 @@ base64 = "0.22.1" bytes = "1.10.0" chrono = "0.4.40" clap = { version = "4.5.31", default-features = false } -clap-verbosity-flag = "3.0.2" clap_complete = "4.5.46" clap_complete_nushell = "4.5.5" concat-idents = "1.1.5" @@ -226,7 +225,6 @@ clap = { workspace = true, features = [ "error-context", "env", ] } -clap-verbosity-flag = { workspace = true } clap_complete = { workspace = true } clap_complete_nushell = { workspace = true } console = { workspace = true, features = ["windows-console-colors"] } diff --git a/crates/pixi_config/src/lib.rs b/crates/pixi_config/src/lib.rs index aca2be9a3..55b012b1d 100644 --- a/crates/pixi_config/src/lib.rs +++ b/crates/pixi_config/src/lib.rs @@ -95,30 +95,30 @@ pub fn get_cache_dir() -> miette::Result { #[derive(Parser, Debug, Default, Clone)] pub struct ConfigCli { /// Do not verify the TLS certificate of the server. - #[arg(long, action = ArgAction::SetTrue)] + #[arg(long, action = ArgAction::SetTrue, help_heading = consts::CLAP_CONFIG_OPTIONS)] tls_no_verify: bool, /// Path to the file containing the authentication token. - #[arg(long)] + #[arg(long, help_heading = consts::CLAP_CONFIG_OPTIONS)] auth_file: Option, /// Specifies whether to use the keyring to look up credentials for PyPI. - #[arg(long)] + #[arg(long, help_heading = consts::CLAP_CONFIG_OPTIONS)] pypi_keyring_provider: Option, /// Max concurrent solves, default is the number of CPUs - #[arg(long)] + #[arg(long, help_heading = consts::CLAP_CONFIG_OPTIONS)] pub concurrent_solves: Option, /// Max concurrent network requests, default is `50` - #[arg(long)] + #[arg(long, help_heading = consts::CLAP_CONFIG_OPTIONS)] pub concurrent_downloads: Option, } #[derive(Parser, Debug, Clone, Default)] pub struct ConfigCliPrompt { /// Do not change the PS1 variable when starting a prompt. - #[arg(long)] + #[arg(long, help_heading = consts::CLAP_CONFIG_OPTIONS)] change_ps1: Option, } @@ -183,11 +183,11 @@ impl RepodataConfig { #[derive(Parser, Debug, Default, Clone)] pub struct ConfigCliActivation { /// Do not use the environment activation cache. (default: true except in experimental mode) - #[arg(long)] + #[arg(long, help_heading = consts::CLAP_CONFIG_OPTIONS)] force_activate: bool, /// Do not source the autocompletion scripts from the environment. - #[arg(long)] + #[arg(long, help_heading = consts::CLAP_CONFIG_OPTIONS)] no_completion: Option, } diff --git a/crates/pixi_consts/src/consts.rs b/crates/pixi_consts/src/consts.rs index 122638a32..9393a3de9 100644 --- a/crates/pixi_consts/src/consts.rs +++ b/crates/pixi_consts/src/consts.rs @@ -83,6 +83,9 @@ pub const ONE_TIME_MESSAGES_DIR: &str = "one-time-messages"; pub const ENVIRONMENT_FILE_NAME: &str = "pixi"; pub const RELEASES_URL: &str = "https://github.com/prefix-dev/pixi/releases"; +pub const CLAP_GLOBAL_OPTIONS: &str = "Global Options"; +pub const CLAP_CONFIG_OPTIONS: &str = "Config Options"; +pub const CLAP_GIT_OPTIONS: &str = "Git Options"; pub static TASK_STYLE: LazyLock