Skip to content

Commit 9486f4c

Browse files
mgeislerkbknapp
authored andcommitted
refactor: simplify initialization of help string
1 parent b93870c commit 9486f4c

File tree

1 file changed

+2
-20
lines changed

1 file changed

+2
-20
lines changed

src/app/help.rs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ impl<'a> Help<'a> {
392392

393393
fn write_before_after_help(&mut self, h: &str) -> io::Result<()> {
394394
debugln!("Help::write_before_after_help;");
395-
let mut help = String::new();
395+
let mut help = String::from(h);
396396
// determine if our help fits or needs to wrap
397397
debugln!("Help::write_before_after_help: Term width...{}",
398398
self.term_w);
@@ -401,7 +401,6 @@ impl<'a> Help<'a> {
401401
debug!("Help::write_before_after_help: Too long...");
402402
if too_long || h.contains("{n}") {
403403
sdebugln!("Yes");
404-
help.push_str(h);
405404
debugln!("Help::write_before_after_help: help: {}", help);
406405
debugln!("Help::write_before_after_help: help width: {}",
407406
str_width(&*help));
@@ -414,12 +413,6 @@ impl<'a> Help<'a> {
414413
} else {
415414
sdebugln!("No");
416415
}
417-
let help = if !help.is_empty() {
418-
&*help
419-
} else {
420-
help.push_str(h);
421-
&*help
422-
};
423416
if help.contains('\n') {
424417
if let Some(part) = help.lines().next() {
425418
try!(write!(self.writer, "{}", part));
@@ -436,12 +429,12 @@ impl<'a> Help<'a> {
436429
/// Writes argument's help to the wrapped stream.
437430
fn help<'b, 'c>(&mut self, arg: &ArgWithDisplay<'b, 'c>, spec_vals: &str) -> io::Result<()> {
438431
debugln!("Help::help;");
439-
let mut help = String::new();
440432
let h = if self.use_long {
441433
arg.long_help().unwrap_or(arg.help().unwrap_or(""))
442434
} else {
443435
arg.help().unwrap_or(arg.long_help().unwrap_or(""))
444436
};
437+
let mut help = String::from(h) + spec_vals;
445438
let nlh = self.next_line_help || arg.is_set(ArgSettings::NextLineHelp) || self.use_long;
446439
debugln!("Help::help: Next Line...{:?}", nlh);
447440

@@ -461,8 +454,6 @@ impl<'a> Help<'a> {
461454
debug!("Help::help: Too long...");
462455
if too_long && spcs <= self.term_w || h.contains("{n}") {
463456
sdebugln!("Yes");
464-
help.push_str(h);
465-
help.push_str(&*spec_vals);
466457
debugln!("Help::help: help...{}", help);
467458
debugln!("Help::help: help width...{}", str_width(&*help));
468459
// Determine how many newlines we need to insert
@@ -474,15 +465,6 @@ impl<'a> Help<'a> {
474465
} else {
475466
sdebugln!("No");
476467
}
477-
let help = if !help.is_empty() {
478-
&*help
479-
} else if spec_vals.is_empty() {
480-
h
481-
} else {
482-
help.push_str(h);
483-
help.push_str(&*spec_vals);
484-
&*help
485-
};
486468
if help.contains('\n') {
487469
if let Some(part) = help.lines().next() {
488470
try!(write!(self.writer, "{}", part));

0 commit comments

Comments
 (0)