Skip to content

Commit

Permalink
Display only feature list or summarized on cargo add
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelin01 committed Sep 19, 2023
1 parent c25bee1 commit b742216
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 119 deletions.
61 changes: 29 additions & 32 deletions src/cargo/ops/cargo_add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -943,56 +943,53 @@ fn print_dep_table_msg(shell: &mut Shell, dep: &DependencyUI) -> CargoResult<()>
if matches!(shell.verbosity(), crate::core::shell::Verbosity::Quiet) {
return Ok(());
}

let (activated, deactivated) = dep.features();
if !activated.is_empty() || !deactivated.is_empty() {
let prefix = format!("{:>13}", " ");
let suffix = format_feature_version_suffix(&dep);
if activated.is_empty() && deactivated.is_empty() {
return Ok(());
}

shell.write_stderr(format_args!("{}Features{}:\n", prefix, suffix), &style::NOP)?;
let prefix = format!("{:>13}", " ");
let suffix = format_features_version_suffix(&dep);

const MAX_FEATURE_PRINTS: usize = 50;
shell.write_stderr(format_args!("{prefix}Features{suffix}:\n"), &style::NOP)?;

let mut activated_printed = 0;
let total_activated = activated.len();
for feat in activated {
if activated_printed >= MAX_FEATURE_PRINTS {
let remaining = total_activated - activated_printed;
shell.write_stderr(
format_args!("{prefix}... {remaining} more activated features\n"),
&style::NOP,
)?;
break;
}
const MAX_FEATURE_PRINTS: usize = 30;
let total_activated = activated.len();
let total_deactivated = deactivated.len();

if total_activated <= MAX_FEATURE_PRINTS {
for feat in activated {
shell.write_stderr(&prefix, &style::NOP)?;
shell.write_stderr('+', &style::GOOD)?;
shell.write_stderr(format_args!(" {}\n", feat), &style::NOP)?;
activated_printed += 1;
shell.write_stderr(format_args!(" {feat}\n"), &style::NOP)?;
}
}
else {
shell.write_stderr(
format_args!("{prefix}{total_activated} activated features\n"),
&style::NOP,
)?;
}

let mut deactivated_printed = 0;
let total_deactivated = deactivated.len();
if total_activated + total_deactivated <= MAX_FEATURE_PRINTS {
for feat in deactivated {
if activated_printed + deactivated_printed >= MAX_FEATURE_PRINTS {
let remaining = total_deactivated - deactivated_printed;
shell.write_stderr(
format_args!("{prefix}... {remaining} more deactivated features\n"),
&style::NOP,
)?;
break;
}

shell.write_stderr(&prefix, &style::NOP)?;
shell.write_stderr('-', &style::ERROR)?;
shell.write_stderr(format_args!(" {}\n", feat), &style::NOP)?;
deactivated_printed += 1;
shell.write_stderr(format_args!(" {feat}\n"), &style::NOP)?;
}
}
else {
shell.write_stderr(
format_args!("{prefix}{total_deactivated} deactivated features\n"),
&style::NOP,
)?;
}

Ok(())
}

fn format_feature_version_suffix(dep: &DependencyUI) -> String {
fn format_features_version_suffix(dep: &DependencyUI) -> String {
if let Some(version) = &dep.available_version {
let mut version = version.clone();
version.build = Default::default();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Updating `dummy-registry` index
Adding your-face v99999.0.0 to dependencies.
Features:
100 activated features
100 deactivated features
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use cargo_test_support::curr_dir;
#[cargo_test]
fn case() {
const MANY_FEATURES_COUNT: usize = 200;
const ACTIVATED_FEATURES_COUNT: usize = 10;
const ACTIVATED_FEATURES_COUNT: usize = 30;

cargo_test_support::registry::init();
let mut test_package =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[workspace]

[package]
name = "cargo-list-test-fixture"
version = "0.0.0"

[dependencies]
your-face = { version = "99999.0.0", features = ["eyes000", "eyes001", "eyes002", "eyes003", "eyes004", "eyes005", "eyes006", "eyes007", "eyes008", "eyes009", "eyes010", "eyes011", "eyes012", "eyes013", "eyes014", "eyes015", "eyes016", "eyes017", "eyes018", "eyes019", "eyes020", "eyes021", "eyes022", "eyes023", "eyes024", "eyes025", "eyes026", "eyes027", "eyes028", "eyes029"] }
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,4 @@
+ eyes027
+ eyes028
+ eyes029
+ eyes030
+ eyes031
+ eyes032
+ eyes033
+ eyes034
+ eyes035
+ eyes036
+ eyes037
+ eyes038
+ eyes039
+ eyes040
+ eyes041
+ eyes042
+ eyes043
+ eyes044
+ eyes045
+ eyes046
+ eyes047
+ eyes048
+ eyes049
... 50 more activated features
... 100 more deactivated features
170 deactivated features

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions tests/testsuite/cargo_add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ mod dev_prefer_existing_version;
mod dry_run;
mod empty_dep_table;
mod features;
mod features_activated_over_limit;
mod features_deactivated_over_limit;
mod features_empty;
mod features_multiple_occurrences;
mod features_preserve;
mod features_spaced_values;
mod features_too_many_activated;
mod features_too_many_few_activated;
mod features_unknown;
mod features_unknown_no_features;
mod git;
Expand Down

0 comments on commit b742216

Please sign in to comment.