mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 06:42:33 +00:00
fix(Help Subcommand): fixes misleading usage string when using multi-level subcommmands
For example, doing `myprog help subcmd1 subcmd2` would have incorrectly produced the usage string, `myprog subcmd2 [options]` but now correctly prints `myprog subcmd1 subcmd2 [options]` Closes #618
This commit is contained in:
parent
9e8e350b95
commit
e203515e3a
1 changed files with 15 additions and 13 deletions
|
@ -235,6 +235,7 @@ impl<'a, 'b> Parser<'a, 'b>
|
||||||
} else {
|
} else {
|
||||||
sdebugln!("No");
|
sdebugln!("No");
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("Using Setting VersionlessSubcommands...");
|
debug!("Using Setting VersionlessSubcommands...");
|
||||||
if self.settings.is_set(AppSettings::VersionlessSubcommands) {
|
if self.settings.is_set(AppSettings::VersionlessSubcommands) {
|
||||||
sdebugln!("Yes");
|
sdebugln!("Yes");
|
||||||
|
@ -620,6 +621,10 @@ impl<'a, 'b> Parser<'a, 'b>
|
||||||
self.settings.is_set(AppSettings::NeedsSubcommandHelp) {
|
self.settings.is_set(AppSettings::NeedsSubcommandHelp) {
|
||||||
let cmds: Vec<OsString> = it.map(|c| c.into()).collect();
|
let cmds: Vec<OsString> = it.map(|c| c.into()).collect();
|
||||||
let mut help_help = false;
|
let mut help_help = false;
|
||||||
|
let mut bin_name = format!("{}", self.meta
|
||||||
|
.bin_name
|
||||||
|
.as_ref()
|
||||||
|
.unwrap_or(&self.meta.name.clone()));
|
||||||
let mut sc = {
|
let mut sc = {
|
||||||
let mut sc: &Parser = self;
|
let mut sc: &Parser = self;
|
||||||
for (i, cmd) in cmds.iter().enumerate() {
|
for (i, cmd) in cmds.iter().enumerate() {
|
||||||
|
@ -663,6 +668,9 @@ impl<'a, 'b> Parser<'a, 'b>
|
||||||
.unwrap_or(&self.meta.name),
|
.unwrap_or(&self.meta.name),
|
||||||
self.color()));
|
self.color()));
|
||||||
}
|
}
|
||||||
|
bin_name = format!("{} {}",
|
||||||
|
bin_name,
|
||||||
|
&*sc.meta.name);
|
||||||
}
|
}
|
||||||
sc.clone()
|
sc.clone()
|
||||||
};
|
};
|
||||||
|
@ -678,17 +686,7 @@ impl<'a, 'b> Parser<'a, 'b>
|
||||||
sc.create_help_and_version();
|
sc.create_help_and_version();
|
||||||
}
|
}
|
||||||
if sc.meta.bin_name != self.meta.bin_name {
|
if sc.meta.bin_name != self.meta.bin_name {
|
||||||
sc.meta.bin_name = Some(format!("{}{}{}",
|
sc.meta.bin_name = Some(format!("{} {}", bin_name, sc.meta.name));
|
||||||
self.meta
|
|
||||||
.bin_name
|
|
||||||
.as_ref()
|
|
||||||
.unwrap_or(&self.meta.name.clone()),
|
|
||||||
if self.meta.bin_name.is_some() {
|
|
||||||
" "
|
|
||||||
} else {
|
|
||||||
""
|
|
||||||
},
|
|
||||||
&*sc.meta.name));
|
|
||||||
}
|
}
|
||||||
return sc._help();
|
return sc._help();
|
||||||
}
|
}
|
||||||
|
@ -1154,9 +1152,13 @@ impl<'a, 'b> Parser<'a, 'b>
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _help(&self) -> ClapResult<()> {
|
fn _help(&self) -> ClapResult<()> {
|
||||||
try!(self.print_help());
|
let mut buf = vec![];
|
||||||
|
try!(Help::write_parser_help(&mut buf, self));
|
||||||
|
let out = io::stdout();
|
||||||
|
let mut out_buf = BufWriter::new(out.lock());
|
||||||
|
try!(out_buf.write(&*buf));
|
||||||
Err(Error {
|
Err(Error {
|
||||||
message: String::new(),
|
message: unsafe { String::from_utf8_unchecked(buf) },
|
||||||
kind: ErrorKind::HelpDisplayed,
|
kind: ErrorKind::HelpDisplayed,
|
||||||
info: None,
|
info: None,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue