Skip to content

Commit fa488a3

Browse files
committed
Print all features when the verbose flag is set
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.
1 parent c5f58e9 commit fa488a3

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/bin/cargo/commands/add.rs

+1
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
226226
section,
227227
dry_run,
228228
honor_rust_version,
229+
verbose: args.verbose() != 0, // just one verbosity level for add.
229230
};
230231
add(&ws, &options)?;
231232

src/cargo/ops/cargo_add/mod.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use crate::core::Package;
2626
use crate::core::Registry;
2727
use crate::core::Shell;
2828
use crate::core::Summary;
29+
use crate::core::Verbosity;
2930
use crate::core::Workspace;
3031
use crate::sources::source::QueryKind;
3132
use crate::util::cache_lock::CacheLockMode;
@@ -60,6 +61,7 @@ pub struct AddOptions<'a> {
6061
pub dry_run: bool,
6162
/// Whether the minimum supported Rust version should be considered during resolution
6263
pub honor_rust_version: Option<bool>,
64+
pub verbose: bool,
6365
}
6466

6567
/// Add dependencies to a manifest
@@ -168,7 +170,7 @@ pub fn add(workspace: &Workspace<'_>, options: &AddOptions<'_>) -> CargoResult<(
168170
write!(message, "no features available for crate {}", dep.name)?;
169171
} else {
170172
if !deactivated.is_empty() {
171-
if deactivated.len() <= MAX_FEATURE_PRINTS {
173+
if options.verbose || deactivated.len() <= MAX_FEATURE_PRINTS {
172174
writeln!(
173175
message,
174176
"disabled features:\n {}",
@@ -188,7 +190,8 @@ pub fn add(workspace: &Workspace<'_>, options: &AddOptions<'_>) -> CargoResult<(
188190
}
189191
}
190192
if !activated.is_empty() {
191-
if deactivated.len() + activated.len() <= MAX_FEATURE_PRINTS {
193+
if options.verbose || deactivated.len() + activated.len() <= MAX_FEATURE_PRINTS
194+
{
192195
writeln!(
193196
message,
194197
"enabled features:\n {}",
@@ -1113,6 +1116,7 @@ fn print_dep_table_msg(shell: &mut Shell, dep: &DependencyUI) -> CargoResult<()>
11131116
return Ok(());
11141117
}
11151118

1119+
let verbose = shell.verbosity() == Verbosity::Verbose;
11161120
let stderr = shell.err();
11171121
let good = style::GOOD;
11181122
let error = style::ERROR;
@@ -1127,15 +1131,15 @@ fn print_dep_table_msg(shell: &mut Shell, dep: &DependencyUI) -> CargoResult<()>
11271131
let total_activated = activated.len();
11281132
let total_deactivated = deactivated.len();
11291133

1130-
if total_activated <= MAX_FEATURE_PRINTS {
1134+
if verbose || total_activated <= MAX_FEATURE_PRINTS {
11311135
for feat in activated {
11321136
writeln!(stderr, "{prefix}{good}+{good:#} {feat}")?;
11331137
}
11341138
} else {
11351139
writeln!(stderr, "{prefix}{total_activated} activated features")?;
11361140
}
11371141

1138-
if total_activated + total_deactivated <= MAX_FEATURE_PRINTS {
1142+
if verbose || total_activated + total_deactivated <= MAX_FEATURE_PRINTS {
11391143
for feat in deactivated {
11401144
writeln!(stderr, "{prefix}{error}-{error:#} {feat}")?;
11411145
}

0 commit comments

Comments
 (0)