Skip to content

Commit 811312c

Browse files
committed
refactor(cli): remove allocation and use format arg capture
1 parent 85b21f8 commit 811312c

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

src/bin/cargo/cli.rs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,36 +61,27 @@ pub fn main(config: &mut LazyConfig) -> CliResult {
6161
let reset = anstyle::Reset.render();
6262

6363
let options = CliUnstable::help();
64-
let non_hidden_options: Vec<(String, String)> = options
65-
.iter()
66-
.filter(|(_, help_message)| *help_message != HIDDEN)
67-
.map(|(name, help)| (name.to_string(), help.to_string()))
68-
.collect();
69-
let longest_option = non_hidden_options
64+
let max_length = options
7065
.iter()
7166
.map(|(option_name, _)| option_name.len())
7267
.max()
73-
.unwrap_or(0);
74-
let help_lines: Vec<String> = non_hidden_options
68+
.unwrap();
69+
let z_flags = options
7570
.iter()
76-
.map(|(option_name, option_help_message)| {
77-
let option_name_kebab_case = option_name.replace("_", "-");
78-
format!(
79-
" {literal}-Z {:<longest_option$}{reset} {}",
80-
option_name_kebab_case, option_help_message
81-
)
71+
.filter(|(_, help)| *help != HIDDEN)
72+
.map(|(opt, help)| {
73+
let opt = opt.replace("_", "-");
74+
format!(" {literal}-Z {opt:<max_length$}{reset} {help}")
8275
})
83-
.collect();
84-
let joined = help_lines.join("\n");
76+
.join("\n");
8577
drop_println!(
8678
config,
8779
"\
8880
{header}Available unstable (nightly-only) flags:{reset}
8981
90-
{}
82+
{z_flags}
9183
9284
Run with `{literal}cargo -Z{reset} {placeholder}[FLAG] [COMMAND]{reset}`",
93-
joined
9485
);
9586
if !config.nightly_features_allowed {
9687
drop_println!(

0 commit comments

Comments
 (0)