Skip to content

Commit

Permalink
Limit features printed during cargo add
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelin01 committed Sep 14, 2023
1 parent 3a40df8 commit 9928689
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 300 deletions.
29 changes: 29 additions & 0 deletions src/cargo/ops/cargo_add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -966,16 +966,45 @@ fn print_dep_table_msg(shell: &mut Shell, dep: &DependencyUI) -> CargoResult<()>
} else {
"".to_owned()
};

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

const MAX_FEATURE_PRINTS: usize = 50;

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;
}

shell.write_stderr(&prefix, &style::NOP)?;
shell.write_stderr('+', &style::GOOD)?;
shell.write_stderr(format_args!(" {}\n", feat), &style::NOP)?;
activated_printed += 1;
}

let mut deactivated_printed = 0;
let total_deactivated = deactivated.len();
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;
}
}

Expand Down
152 changes: 2 additions & 150 deletions tests/testsuite/cargo_add/features_too_many_activated/stderr.log
Original file line number Diff line number Diff line change
Expand Up @@ -51,153 +51,5 @@
+ eyes047
+ eyes048
+ eyes049
+ eyes050
+ eyes051
+ eyes052
+ eyes053
+ eyes054
+ eyes055
+ eyes056
+ eyes057
+ eyes058
+ eyes059
+ eyes060
+ eyes061
+ eyes062
+ eyes063
+ eyes064
+ eyes065
+ eyes066
+ eyes067
+ eyes068
+ eyes069
+ eyes070
+ eyes071
+ eyes072
+ eyes073
+ eyes074
+ eyes075
+ eyes076
+ eyes077
+ eyes078
+ eyes079
+ eyes080
+ eyes081
+ eyes082
+ eyes083
+ eyes084
+ eyes085
+ eyes086
+ eyes087
+ eyes088
+ eyes089
+ eyes090
+ eyes091
+ eyes092
+ eyes093
+ eyes094
+ eyes095
+ eyes096
+ eyes097
+ eyes098
+ eyes099
- eyes100
- eyes101
- eyes102
- eyes103
- eyes104
- eyes105
- eyes106
- eyes107
- eyes108
- eyes109
- eyes110
- eyes111
- eyes112
- eyes113
- eyes114
- eyes115
- eyes116
- eyes117
- eyes118
- eyes119
- eyes120
- eyes121
- eyes122
- eyes123
- eyes124
- eyes125
- eyes126
- eyes127
- eyes128
- eyes129
- eyes130
- eyes131
- eyes132
- eyes133
- eyes134
- eyes135
- eyes136
- eyes137
- eyes138
- eyes139
- eyes140
- eyes141
- eyes142
- eyes143
- eyes144
- eyes145
- eyes146
- eyes147
- eyes148
- eyes149
- eyes150
- eyes151
- eyes152
- eyes153
- eyes154
- eyes155
- eyes156
- eyes157
- eyes158
- eyes159
- eyes160
- eyes161
- eyes162
- eyes163
- eyes164
- eyes165
- eyes166
- eyes167
- eyes168
- eyes169
- eyes170
- eyes171
- eyes172
- eyes173
- eyes174
- eyes175
- eyes176
- eyes177
- eyes178
- eyes179
- eyes180
- eyes181
- eyes182
- eyes183
- eyes184
- eyes185
- eyes186
- eyes187
- eyes188
- eyes189
- eyes190
- eyes191
- eyes192
- eyes193
- eyes194
- eyes195
- eyes196
- eyes197
- eyes198
- eyes199
... 50 more activated features
... 100 more deactivated features
151 changes: 1 addition & 150 deletions tests/testsuite/cargo_add/features_too_many_few_activated/stderr.log
Original file line number Diff line number Diff line change
Expand Up @@ -51,153 +51,4 @@
- eyes047
- eyes048
- eyes049
- eyes050
- eyes051
- eyes052
- eyes053
- eyes054
- eyes055
- eyes056
- eyes057
- eyes058
- eyes059
- eyes060
- eyes061
- eyes062
- eyes063
- eyes064
- eyes065
- eyes066
- eyes067
- eyes068
- eyes069
- eyes070
- eyes071
- eyes072
- eyes073
- eyes074
- eyes075
- eyes076
- eyes077
- eyes078
- eyes079
- eyes080
- eyes081
- eyes082
- eyes083
- eyes084
- eyes085
- eyes086
- eyes087
- eyes088
- eyes089
- eyes090
- eyes091
- eyes092
- eyes093
- eyes094
- eyes095
- eyes096
- eyes097
- eyes098
- eyes099
- eyes100
- eyes101
- eyes102
- eyes103
- eyes104
- eyes105
- eyes106
- eyes107
- eyes108
- eyes109
- eyes110
- eyes111
- eyes112
- eyes113
- eyes114
- eyes115
- eyes116
- eyes117
- eyes118
- eyes119
- eyes120
- eyes121
- eyes122
- eyes123
- eyes124
- eyes125
- eyes126
- eyes127
- eyes128
- eyes129
- eyes130
- eyes131
- eyes132
- eyes133
- eyes134
- eyes135
- eyes136
- eyes137
- eyes138
- eyes139
- eyes140
- eyes141
- eyes142
- eyes143
- eyes144
- eyes145
- eyes146
- eyes147
- eyes148
- eyes149
- eyes150
- eyes151
- eyes152
- eyes153
- eyes154
- eyes155
- eyes156
- eyes157
- eyes158
- eyes159
- eyes160
- eyes161
- eyes162
- eyes163
- eyes164
- eyes165
- eyes166
- eyes167
- eyes168
- eyes169
- eyes170
- eyes171
- eyes172
- eyes173
- eyes174
- eyes175
- eyes176
- eyes177
- eyes178
- eyes179
- eyes180
- eyes181
- eyes182
- eyes183
- eyes184
- eyes185
- eyes186
- eyes187
- eyes188
- eyes189
- eyes190
- eyes191
- eyes192
- eyes193
- eyes194
- eyes195
- eyes196
- eyes197
- eyes198
- eyes199
... 150 more deactivated features

0 comments on commit 9928689

Please sign in to comment.