Skip to content

Commit 82f07f1

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 82f07f1

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/bin/cargo/commands/add.rs

+2
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,9 @@ 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
};
231+
230232
add(&ws, &options)?;
231233

232234
// Reload the workspace since we've changed dependencies

src/cargo/ops/cargo_add/mod.rs

+9-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
@@ -122,6 +124,7 @@ pub fn add(workspace: &Workspace<'_>, options: &AddOptions<'_>) -> CargoResult<(
122124
.is_sorted()
123125
})
124126
});
127+
125128
for dep in deps {
126129
print_action_msg(&mut options.gctx.shell(), &dep, &dep_table)?;
127130
if let Some(Source::Path(src)) = dep.source() {
@@ -168,7 +171,7 @@ pub fn add(workspace: &Workspace<'_>, options: &AddOptions<'_>) -> CargoResult<(
168171
write!(message, "no features available for crate {}", dep.name)?;
169172
} else {
170173
if !deactivated.is_empty() {
171-
if deactivated.len() <= MAX_FEATURE_PRINTS {
174+
if options.verbose || deactivated.len() <= MAX_FEATURE_PRINTS {
172175
writeln!(
173176
message,
174177
"disabled features:\n {}",
@@ -188,7 +191,8 @@ pub fn add(workspace: &Workspace<'_>, options: &AddOptions<'_>) -> CargoResult<(
188191
}
189192
}
190193
if !activated.is_empty() {
191-
if deactivated.len() + activated.len() <= MAX_FEATURE_PRINTS {
194+
if options.verbose || deactivated.len() + activated.len() <= MAX_FEATURE_PRINTS
195+
{
192196
writeln!(
193197
message,
194198
"enabled features:\n {}",
@@ -1113,6 +1117,7 @@ fn print_dep_table_msg(shell: &mut Shell, dep: &DependencyUI) -> CargoResult<()>
11131117
return Ok(());
11141118
}
11151119

1120+
let verbose = shell.verbosity() == Verbosity::Verbose;
11161121
let stderr = shell.err();
11171122
let good = style::GOOD;
11181123
let error = style::ERROR;
@@ -1127,15 +1132,15 @@ fn print_dep_table_msg(shell: &mut Shell, dep: &DependencyUI) -> CargoResult<()>
11271132
let total_activated = activated.len();
11281133
let total_deactivated = deactivated.len();
11291134

1130-
if total_activated <= MAX_FEATURE_PRINTS {
1135+
if verbose || total_activated <= MAX_FEATURE_PRINTS {
11311136
for feat in activated {
11321137
writeln!(stderr, "{prefix}{good}+{good:#} {feat}")?;
11331138
}
11341139
} else {
11351140
writeln!(stderr, "{prefix}{total_activated} activated features")?;
11361141
}
11371142

1138-
if total_activated + total_deactivated <= MAX_FEATURE_PRINTS {
1143+
if verbose || total_activated + total_deactivated <= MAX_FEATURE_PRINTS {
11391144
for feat in deactivated {
11401145
writeln!(stderr, "{prefix}{error}-{error:#} {feat}")?;
11411146
}

0 commit comments

Comments
 (0)