forked from mirrors/jj
commands: print help if no sub[sub]command given
I didn't know about the Clap setting to print help if no subcommand was given, so I had reimplemented that myself for the top-level command. However, if the user did e.g. `jj git`, they'd get a crash. This commit fixes that by turning on the setting.
This commit is contained in:
parent
3a67952215
commit
aea1ea3707
1 changed files with 5 additions and 7 deletions
|
@ -409,6 +409,7 @@ fn get_app<'a, 'b>() -> App<'a, 'b> {
|
||||||
let operation_command = SubCommand::with_name("operation")
|
let operation_command = SubCommand::with_name("operation")
|
||||||
.alias("op")
|
.alias("op")
|
||||||
.about("commands for working with the operation log")
|
.about("commands for working with the operation log")
|
||||||
|
.setting(clap::AppSettings::SubcommandRequiredElseHelp)
|
||||||
.subcommand(SubCommand::with_name("log").about("show the operation log"))
|
.subcommand(SubCommand::with_name("log").about("show the operation log"))
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name("undo")
|
SubCommand::with_name("undo")
|
||||||
|
@ -422,6 +423,7 @@ fn get_app<'a, 'b>() -> App<'a, 'b> {
|
||||||
);
|
);
|
||||||
let git_command = SubCommand::with_name("git")
|
let git_command = SubCommand::with_name("git")
|
||||||
.about("commands for working with the underlying git repo")
|
.about("commands for working with the underlying git repo")
|
||||||
|
.setting(clap::AppSettings::SubcommandRequiredElseHelp)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name("push")
|
SubCommand::with_name("push")
|
||||||
.about("push a revision to a git remote branch")
|
.about("push a revision to a git remote branch")
|
||||||
|
@ -451,6 +453,7 @@ fn get_app<'a, 'b>() -> App<'a, 'b> {
|
||||||
);
|
);
|
||||||
let bench_command = SubCommand::with_name("bench")
|
let bench_command = SubCommand::with_name("bench")
|
||||||
.about("commands for benchmarking internal operations")
|
.about("commands for benchmarking internal operations")
|
||||||
|
.setting(clap::AppSettings::SubcommandRequiredElseHelp)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name("commonancestors")
|
SubCommand::with_name("commonancestors")
|
||||||
.about("finds the common ancestor(s) of a set of commits")
|
.about("finds the common ancestor(s) of a set of commits")
|
||||||
|
@ -476,6 +479,7 @@ fn get_app<'a, 'b>() -> App<'a, 'b> {
|
||||||
);
|
);
|
||||||
let debug_command = SubCommand::with_name("debug")
|
let debug_command = SubCommand::with_name("debug")
|
||||||
.about("low-level commands not intended for users")
|
.about("low-level commands not intended for users")
|
||||||
|
.setting(clap::AppSettings::SubcommandRequiredElseHelp)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name("resolverev")
|
SubCommand::with_name("resolverev")
|
||||||
.about("resolves a revision identifier to its full id")
|
.about("resolves a revision identifier to its full id")
|
||||||
|
@ -498,6 +502,7 @@ fn get_app<'a, 'b>() -> App<'a, 'b> {
|
||||||
.subcommand(SubCommand::with_name("reindex").about("rebuild commit index"));
|
.subcommand(SubCommand::with_name("reindex").about("rebuild commit index"));
|
||||||
App::new("Jujube")
|
App::new("Jujube")
|
||||||
.global_setting(clap::AppSettings::ColoredHelp)
|
.global_setting(clap::AppSettings::ColoredHelp)
|
||||||
|
.setting(clap::AppSettings::SubcommandRequiredElseHelp)
|
||||||
.version("0.0.1")
|
.version("0.0.1")
|
||||||
.author("Martin von Zweigbergk <martinvonz@google.com>")
|
.author("Martin von Zweigbergk <martinvonz@google.com>")
|
||||||
.about("My source control tool")
|
.about("My source control tool")
|
||||||
|
@ -2028,13 +2033,6 @@ where
|
||||||
T: Into<OsString> + Clone,
|
T: Into<OsString> + Clone,
|
||||||
{
|
{
|
||||||
let matches = get_app().get_matches_from(args);
|
let matches = get_app().get_matches_from(args);
|
||||||
if matches.subcommand_name().is_none() {
|
|
||||||
let mut help_text_buf = Vec::new();
|
|
||||||
get_app().write_long_help(&mut help_text_buf).unwrap();
|
|
||||||
ui.write(String::from_utf8(help_text_buf).unwrap().as_str());
|
|
||||||
ui.write("\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
let result = if let Some(sub_matches) = matches.subcommand_matches("init") {
|
let result = if let Some(sub_matches) = matches.subcommand_matches("init") {
|
||||||
cmd_init(&mut ui, &matches, &sub_matches)
|
cmd_init(&mut ui, &matches, &sub_matches)
|
||||||
} else if let Some(sub_matches) = matches.subcommand_matches("checkout") {
|
} else if let Some(sub_matches) = matches.subcommand_matches("checkout") {
|
||||||
|
|
Loading…
Reference in a new issue