From fa488a3c9ea6f480fcd0e3cc8151ca42ace54bed Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 1 Apr 2025 12:19:33 +0200 Subject: [PATCH] Print all features when the verbose flag is set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, the dependency printing has a hardcoded limit, and for some crates it's useful to see a bit more. I understand why the hard limit is set, but we already have a verbose flag, let's use it and let the user decide if he wants to see something more. My case was the crate `reqest`, that listed for me as: ``` ➜ cargo add reqwest Updating crates.io index Adding reqwest v0.12.15 to dependencies Features: + __tls + charset + default-tls + h2 + http2 + macos-system-configuration 26 deactivated features ``` What are those deactivated features? I had to use the browser to discover, whereas it's much more confortable for me to just do a small pipe to grep and `-` to see only the features I care about: the ones that are disabled, and I might need to add to my project. Overall, this is a really small change, but made my life easier. --- src/bin/cargo/commands/add.rs | 1 + src/cargo/ops/cargo_add/mod.rs | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/bin/cargo/commands/add.rs b/src/bin/cargo/commands/add.rs index de9f382ea01..eb6fb56fe8f 100644 --- a/src/bin/cargo/commands/add.rs +++ b/src/bin/cargo/commands/add.rs @@ -226,6 +226,7 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult { section, dry_run, honor_rust_version, + verbose: args.verbose() != 0, // just one verbosity level for add. }; add(&ws, &options)?; diff --git a/src/cargo/ops/cargo_add/mod.rs b/src/cargo/ops/cargo_add/mod.rs index d872e2f0096..b779f034494 100644 --- a/src/cargo/ops/cargo_add/mod.rs +++ b/src/cargo/ops/cargo_add/mod.rs @@ -26,6 +26,7 @@ use crate::core::Package; use crate::core::Registry; use crate::core::Shell; use crate::core::Summary; +use crate::core::Verbosity; use crate::core::Workspace; use crate::sources::source::QueryKind; use crate::util::cache_lock::CacheLockMode; @@ -60,6 +61,7 @@ pub struct AddOptions<'a> { pub dry_run: bool, /// Whether the minimum supported Rust version should be considered during resolution pub honor_rust_version: Option, + pub verbose: bool, } /// Add dependencies to a manifest @@ -168,7 +170,7 @@ pub fn add(workspace: &Workspace<'_>, options: &AddOptions<'_>) -> CargoResult<( write!(message, "no features available for crate {}", dep.name)?; } else { if !deactivated.is_empty() { - if deactivated.len() <= MAX_FEATURE_PRINTS { + if options.verbose || deactivated.len() <= MAX_FEATURE_PRINTS { writeln!( message, "disabled features:\n {}", @@ -188,7 +190,8 @@ pub fn add(workspace: &Workspace<'_>, options: &AddOptions<'_>) -> CargoResult<( } } if !activated.is_empty() { - if deactivated.len() + activated.len() <= MAX_FEATURE_PRINTS { + if options.verbose || deactivated.len() + activated.len() <= MAX_FEATURE_PRINTS + { writeln!( message, "enabled features:\n {}", @@ -1113,6 +1116,7 @@ fn print_dep_table_msg(shell: &mut Shell, dep: &DependencyUI) -> CargoResult<()> return Ok(()); } + let verbose = shell.verbosity() == Verbosity::Verbose; let stderr = shell.err(); let good = style::GOOD; let error = style::ERROR; @@ -1127,7 +1131,7 @@ fn print_dep_table_msg(shell: &mut Shell, dep: &DependencyUI) -> CargoResult<()> let total_activated = activated.len(); let total_deactivated = deactivated.len(); - if total_activated <= MAX_FEATURE_PRINTS { + if verbose || total_activated <= MAX_FEATURE_PRINTS { for feat in activated { writeln!(stderr, "{prefix}{good}+{good:#} {feat}")?; } @@ -1135,7 +1139,7 @@ fn print_dep_table_msg(shell: &mut Shell, dep: &DependencyUI) -> CargoResult<()> writeln!(stderr, "{prefix}{total_activated} activated features")?; } - if total_activated + total_deactivated <= MAX_FEATURE_PRINTS { + if verbose || total_activated + total_deactivated <= MAX_FEATURE_PRINTS { for feat in deactivated { writeln!(stderr, "{prefix}{error}-{error:#} {feat}")?; }