Skip to content

Commit 4505821

Browse files
committed
feat: always show features available for a dependency on cargo add
1 parent aed94a8 commit 4505821

File tree

8 files changed

+119
-48
lines changed

8 files changed

+119
-48
lines changed

src/cargo/ops/cargo_add/mod.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ pub fn add(workspace: &Workspace<'_>, options: &AddOptions<'_>) -> CargoResult<(
152152

153153
unknown_features.sort();
154154

155+
print_dep_table_msg(&mut options.gctx.shell(), &dep, &unknown_features)?;
156+
155157
if !unknown_features.is_empty() {
156158
let (mut activated, mut deactivated) = dep.features();
157159
// Since the unknown features have been added to the DependencyUI we need to remove
@@ -233,8 +235,6 @@ pub fn add(workspace: &Workspace<'_>, options: &AddOptions<'_>) -> CargoResult<(
233235
anyhow::bail!(message.trim().to_owned());
234236
}
235237

236-
print_dep_table_msg(&mut options.gctx.shell(), &dep)?;
237-
238238
manifest.insert_into_table(
239239
&dep_table,
240240
&dep,
@@ -1130,7 +1130,11 @@ fn print_action_msg(shell: &mut Shell, dep: &DependencyUI, section: &[String]) -
11301130
shell.status("Adding", message)
11311131
}
11321132

1133-
fn print_dep_table_msg(shell: &mut Shell, dep: &DependencyUI) -> CargoResult<()> {
1133+
fn print_dep_table_msg(
1134+
shell: &mut Shell,
1135+
dep: &DependencyUI,
1136+
unknown_features: &Vec<&str>,
1137+
) -> CargoResult<()> {
11341138
if matches!(shell.verbosity(), crate::core::shell::Verbosity::Quiet) {
11351139
return Ok(());
11361140
}
@@ -1140,6 +1144,15 @@ fn print_dep_table_msg(shell: &mut Shell, dep: &DependencyUI) -> CargoResult<()>
11401144
let error = style::ERROR;
11411145

11421146
let (activated, deactivated) = dep.features();
1147+
let activated: Vec<&str> = activated
1148+
.into_iter()
1149+
.filter(|&feature_name| {
1150+
!unknown_features
1151+
.iter()
1152+
.any(|&unknown_feature| unknown_feature == feature_name)
1153+
})
1154+
.collect();
1155+
11431156
if !activated.is_empty() || !deactivated.is_empty() {
11441157
let prefix = format!("{:>13}", " ");
11451158
let suffix = format_features_version_suffix(&dep);

tests/testsuite/cargo_add/feature_suggestion_multiple/stderr.term.svg

Lines changed: 13 additions & 7 deletions
Loading

tests/testsuite/cargo_add/feature_suggestion_none/stderr.term.svg

Lines changed: 11 additions & 5 deletions
Loading

tests/testsuite/cargo_add/feature_suggestion_single/stderr.term.svg

Lines changed: 8 additions & 4 deletions
Loading

tests/testsuite/cargo_add/features_error_activated_over_limit/stderr.term.svg

Lines changed: 13 additions & 7 deletions
Loading

tests/testsuite/cargo_add/features_error_deactivated_over_limit/stderr.term.svg

Lines changed: 13 additions & 7 deletions
Loading

tests/testsuite/cargo_add/features_unknown/stderr.term.svg

Lines changed: 15 additions & 5 deletions
Loading

tests/testsuite/cargo_add/unknown_inherited_feature/stderr.term.svg

Lines changed: 30 additions & 10 deletions
Loading

0 commit comments

Comments
 (0)