forked from mirrors/jj
cli: do not raise ClapError from resolve_aliases()
This allows us to process early args after alias resolution.
This commit is contained in:
parent
aa2ce88544
commit
5dc73ab7ad
2 changed files with 48 additions and 2 deletions
|
@ -1414,8 +1414,8 @@ fn resolve_aliases(
|
||||||
}
|
}
|
||||||
loop {
|
loop {
|
||||||
let app_clone = app.clone().allow_external_subcommands(true);
|
let app_clone = app.clone().allow_external_subcommands(true);
|
||||||
let matches = app_clone.try_get_matches_from(&string_args)?;
|
let matches = app_clone.try_get_matches_from(&string_args).ok();
|
||||||
if let Some((command_name, submatches)) = matches.subcommand() {
|
if let Some((command_name, submatches)) = matches.as_ref().and_then(|m| m.subcommand()) {
|
||||||
if !real_commands.contains(command_name) {
|
if !real_commands.contains(command_name) {
|
||||||
let alias_name = command_name.to_string();
|
let alias_name = command_name.to_string();
|
||||||
let alias_args = submatches
|
let alias_args = submatches
|
||||||
|
@ -1447,6 +1447,7 @@ fn resolve_aliases(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// No more alias commands, or hit unknown option
|
||||||
return Ok(string_args);
|
return Ok(string_args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
use itertools::Itertools as _;
|
||||||
|
|
||||||
use crate::common::TestEnvironment;
|
use crate::common::TestEnvironment;
|
||||||
|
|
||||||
pub mod common;
|
pub mod common;
|
||||||
|
@ -72,6 +74,49 @@ fn test_alias_calls_unknown_command() {
|
||||||
"###);
|
"###);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_alias_calls_command_with_invalid_option() {
|
||||||
|
let test_env = TestEnvironment::default();
|
||||||
|
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
|
||||||
|
let repo_path = test_env.env_root().join("repo");
|
||||||
|
|
||||||
|
test_env.add_config(
|
||||||
|
br#"[alias]
|
||||||
|
foo = ["log", "--nonexistent"]
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
let stderr = test_env.jj_cmd_cli_error(&repo_path, &["foo"]);
|
||||||
|
insta::assert_snapshot!(stderr, @r###"
|
||||||
|
error: Found argument '--nonexistent' which wasn't expected, or isn't valid in this context
|
||||||
|
|
||||||
|
If you tried to supply '--nonexistent' as a value rather than a flag, use '-- --nonexistent'
|
||||||
|
|
||||||
|
Usage: jj log [OPTIONS] [PATHS]...
|
||||||
|
|
||||||
|
For more information try '--help'
|
||||||
|
"###);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_alias_calls_help() {
|
||||||
|
let test_env = TestEnvironment::default();
|
||||||
|
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
|
||||||
|
let repo_path = test_env.env_root().join("repo");
|
||||||
|
test_env.add_config(
|
||||||
|
br#"[alias]
|
||||||
|
h = ["--help"]
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
let stdout = test_env.jj_cmd_success(&repo_path, &["h"]);
|
||||||
|
insta::assert_snapshot!(stdout.lines().take(5).join("\n"), @r###"
|
||||||
|
Jujutsu (An experimental VCS)
|
||||||
|
|
||||||
|
To get started, see the tutorial at https://github.com/martinvonz/jj/blob/main/docs/tutorial.md.
|
||||||
|
|
||||||
|
Usage: jj [OPTIONS] <COMMAND>
|
||||||
|
"###);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_alias_cannot_override_builtin() {
|
fn test_alias_cannot_override_builtin() {
|
||||||
let test_env = TestEnvironment::default();
|
let test_env = TestEnvironment::default();
|
||||||
|
|
Loading…
Reference in a new issue