From e3b6fc8f5baa3ecadd46a1f6d52507775c0ae2bb Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 22 Mar 2024 09:32:40 -0500 Subject: [PATCH] fix: Don't overwhelm the user with features This was modeled after the work done in `cargo-add` in rust-lang/cargo#12702 --- src/ops/view.rs | 47 ++-- .../features_activated_over_limit/stdout.log | 203 +----------------- .../stdout.log | 181 +--------------- 3 files changed, 36 insertions(+), 395 deletions(-) diff --git a/src/ops/view.rs b/src/ops/view.rs index acaefaf..da30aa2 100644 --- a/src/ops/view.rs +++ b/src/ops/view.rs @@ -243,6 +243,7 @@ fn pretty_features(features: &FeatureMap, stdout: &mut dyn Write) -> CargoResult let header = HEADER; let enabled = LITERAL; let disabled = NOP; + let summary = anstyle::Style::new() | anstyle::Effects::ITALIC; // If there are no features, return early. let margin = features @@ -276,26 +277,44 @@ fn pretty_features(features: &FeatureMap, stdout: &mut dyn Write) -> CargoResult activated.push((current, current_activated)); } - for (current, current_activated) in activated { + const MAX_FEATURE_PRINTS: usize = 30; + let total_activated = activated.len(); + let total_deactivated = remaining.len(); + if total_activated <= MAX_FEATURE_PRINTS { + for (current, current_activated) in activated { + writeln!( + stdout, + " {enabled}{current: >() + .join(", ") + )?; + } + } else { writeln!( stdout, - " {enabled}{current: >() - .join(", ") + " {summary}{total_activated} activated features{summary:#}", )?; } - for (current, current_activated) in remaining { + + if (total_activated + total_deactivated) <= MAX_FEATURE_PRINTS { + for (current, current_activated) in remaining { + writeln!( + stdout, + " {disabled}{current: >() + .join(", ") + )?; + } + } else { writeln!( stdout, - " {disabled}{current: >() - .join(", ") + " {summary}{total_deactivated} deactivated features{summary:#}", )?; } diff --git a/tests/testsuite/cargo_information/features_activated_over_limit/stdout.log b/tests/testsuite/cargo_information/features_activated_over_limit/stdout.log index 67cc960..29cc84d 100644 --- a/tests/testsuite/cargo_information/features_activated_over_limit/stdout.log +++ b/tests/testsuite/cargo_information/features_activated_over_limit/stdout.log @@ -3,204 +3,5 @@ version: 99999.0.0+my-package (from registry `dummy-registry`) license: unknown rust-version: unknown features: - default = [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, eyes030, eyes031, eyes032, eyes033, eyes034, eyes035, eyes036, eyes037, eyes038, eyes039, eyes040, eyes041, eyes042, eyes043, eyes044, eyes045, eyes046, 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] - 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 = [] - eyes030 = [] - eyes031 = [] - eyes032 = [] - eyes033 = [] - eyes034 = [] - eyes035 = [] - eyes036 = [] - eyes037 = [] - eyes038 = [] - eyes039 = [] - eyes040 = [] - eyes041 = [] - eyes042 = [] - eyes043 = [] - eyes044 = [] - eyes045 = [] - eyes046 = [] - 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 = [] + 101 activated features + 100 deactivated features diff --git a/tests/testsuite/cargo_information/features_deactivated_over_limit/stdout.log b/tests/testsuite/cargo_information/features_deactivated_over_limit/stdout.log index fd7d14b..98ab529 100644 --- a/tests/testsuite/cargo_information/features_deactivated_over_limit/stdout.log +++ b/tests/testsuite/cargo_information/features_deactivated_over_limit/stdout.log @@ -24,183 +24,4 @@ features: eyes017 = [] eyes018 = [] eyes019 = [] - eyes020 = [] - eyes021 = [] - eyes022 = [] - eyes023 = [] - eyes024 = [] - eyes025 = [] - eyes026 = [] - eyes027 = [] - eyes028 = [] - eyes029 = [] - eyes030 = [] - eyes031 = [] - eyes032 = [] - eyes033 = [] - eyes034 = [] - eyes035 = [] - eyes036 = [] - eyes037 = [] - eyes038 = [] - eyes039 = [] - eyes040 = [] - eyes041 = [] - eyes042 = [] - eyes043 = [] - eyes044 = [] - eyes045 = [] - eyes046 = [] - 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 = [] + 180 deactivated features