Skip to content

Commit 524d123

Browse files
committed
fix(add): Focus on error, rather than large feature lists
Inspired by #11100 and previous work to collapse feature lists down.
1 parent 4a0b894 commit 524d123

File tree

3 files changed

+43
-93
lines changed

3 files changed

+43
-93
lines changed

src/cargo/ops/cargo_add/mod.rs

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -168,36 +168,44 @@ pub fn add(workspace: &Workspace<'_>, options: &AddOptions<'_>) -> CargoResult<(
168168
write!(message, "no features available for crate {}", dep.name)?;
169169
} else {
170170
if !deactivated.is_empty() {
171-
writeln!(
172-
message,
173-
"disabled features:\n {}",
174-
deactivated
175-
.iter()
176-
.map(|s| s.to_string())
177-
.coalesce(|x, y| if x.len() + y.len() < 78 {
178-
Ok(format!("{x}, {y}"))
179-
} else {
180-
Err((x, y))
181-
})
182-
.into_iter()
183-
.format("\n ")
184-
)?
171+
if deactivated.len() <= MAX_FEATURE_PRINTS {
172+
writeln!(
173+
message,
174+
"disabled features:\n {}",
175+
deactivated
176+
.iter()
177+
.map(|s| s.to_string())
178+
.coalesce(|x, y| if x.len() + y.len() < 78 {
179+
Ok(format!("{x}, {y}"))
180+
} else {
181+
Err((x, y))
182+
})
183+
.into_iter()
184+
.format("\n ")
185+
)?;
186+
} else {
187+
writeln!(message, "{} disabled features available", deactivated.len())?;
188+
}
185189
}
186190
if !activated.is_empty() {
187-
writeln!(
188-
message,
189-
"enabled features:\n {}",
190-
activated
191-
.iter()
192-
.map(|s| s.to_string())
193-
.coalesce(|x, y| if x.len() + y.len() < 78 {
194-
Ok(format!("{x}, {y}"))
195-
} else {
196-
Err((x, y))
197-
})
198-
.into_iter()
199-
.format("\n ")
200-
)?
191+
if deactivated.len() + activated.len() <= MAX_FEATURE_PRINTS {
192+
writeln!(
193+
message,
194+
"enabled features:\n {}",
195+
activated
196+
.iter()
197+
.map(|s| s.to_string())
198+
.coalesce(|x, y| if x.len() + y.len() < 78 {
199+
Ok(format!("{x}, {y}"))
200+
} else {
201+
Err((x, y))
202+
})
203+
.into_iter()
204+
.format("\n ")
205+
)?;
206+
} else {
207+
writeln!(message, "{} enabled features available", activated.len())?;
208+
}
201209
}
202210
}
203211
anyhow::bail!(message.trim().to_owned());

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

Lines changed: 3 additions & 13 deletions
Loading

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

Lines changed: 4 additions & 52 deletions
Loading

0 commit comments

Comments
 (0)