forked from mirrors/jj
cli: don't panic on empty alias substitution
This partially reverts 6c627fb30d
"cli: default to log when no subcommand is
provided." We could reject an empty alias at all, but we would still need to
ensure that the expanded alias contained a subcommand name.
The help output is a bit odd as the <COMMAND> can be omitted, but I think
that's acceptable. If we do care about that, maybe we can override_usage().
This commit is contained in:
parent
b954bab0ca
commit
6b862c6f23
2 changed files with 36 additions and 4 deletions
|
@ -2777,7 +2777,11 @@ pub fn parse_args(
|
|||
layered_configs: &mut LayeredConfigs,
|
||||
) -> Result<(ArgMatches, Args), CommandError> {
|
||||
handle_early_args(ui, app, string_args, layered_configs)?;
|
||||
let matches = app.clone().try_get_matches_from(string_args)?;
|
||||
let matches = app
|
||||
.clone()
|
||||
.arg_required_else_help(true)
|
||||
.subcommand_required(true)
|
||||
.try_get_matches_from(string_args)?;
|
||||
|
||||
let args: Args = Args::from_arg_matches(&matches).unwrap();
|
||||
if args.global_args.verbose {
|
||||
|
|
|
@ -71,12 +71,40 @@ fn test_alias_bad_name() {
|
|||
insta::assert_snapshot!(stderr, @r###"
|
||||
error: unrecognized subcommand 'foo.'
|
||||
|
||||
Usage: jj [OPTIONS] [COMMAND]
|
||||
Usage: jj [OPTIONS] <COMMAND>
|
||||
|
||||
For more information, try '--help'.
|
||||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_alias_calls_empty_command() {
|
||||
let test_env = TestEnvironment::default();
|
||||
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
|
||||
let repo_path = test_env.env_root().join("repo");
|
||||
|
||||
test_env.add_config(
|
||||
r#"
|
||||
aliases.empty = []
|
||||
aliases.empty_command_with_opts = ["--no-pager"]
|
||||
"#,
|
||||
);
|
||||
let stderr = test_env.jj_cmd_cli_error(&repo_path, &["empty"]);
|
||||
insta::assert_snapshot!(stderr.lines().take(3).join("\n"), @r###"
|
||||
Jujutsu (An experimental VCS)
|
||||
|
||||
Usage: jj [OPTIONS] <COMMAND>
|
||||
"###);
|
||||
let stderr = test_env.jj_cmd_cli_error(&repo_path, &["empty", "--no-pager"]);
|
||||
insta::assert_snapshot!(stderr.lines().next().unwrap_or_default(), @r###"
|
||||
error: 'jj' requires a subcommand but one was not provided
|
||||
"###);
|
||||
let stderr = test_env.jj_cmd_cli_error(&repo_path, &["empty_command_with_opts"]);
|
||||
insta::assert_snapshot!(stderr.lines().next().unwrap_or_default(), @r###"
|
||||
error: 'jj' requires a subcommand but one was not provided
|
||||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_alias_calls_unknown_command() {
|
||||
let test_env = TestEnvironment::default();
|
||||
|
@ -90,7 +118,7 @@ fn test_alias_calls_unknown_command() {
|
|||
|
||||
tip: a similar subcommand exists: 'next'
|
||||
|
||||
Usage: jj [OPTIONS] [COMMAND]
|
||||
Usage: jj [OPTIONS] <COMMAND>
|
||||
|
||||
For more information, try '--help'.
|
||||
"###);
|
||||
|
@ -127,7 +155,7 @@ fn test_alias_calls_help() {
|
|||
|
||||
To get started, see the tutorial at https://github.com/martinvonz/jj/blob/main/docs/tutorial.md.
|
||||
|
||||
Usage: jj [OPTIONS] [COMMAND]
|
||||
Usage: jj [OPTIONS] <COMMAND>
|
||||
"###);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue