ok/jj
1
0
Fork 0
forked from mirrors/jj

cli_util: support multiple cli arguments for ui.default-command

This commit is contained in:
dploch 2024-03-02 17:40:00 -05:00 committed by Daniel Ploch
parent bf76080f42
commit b4c4d91190
4 changed files with 41 additions and 6 deletions

View file

@ -106,6 +106,9 @@ No code changes (fixing Rust `Cargo.toml` stuff).
defined template names when no argument is given, assisting the user in making
a selection.
* `ui.default-command` now accepts multiple string arguments, for more complex
default `jj` commands.
### Fixed bugs
* On Windows, symlinks in the repo are now supported when Developer Mode is enabled.

View file

@ -2171,6 +2171,16 @@ impl ValueParserFactory for RevisionArg {
}
}
fn get_string_or_array(
config: &config::Config,
key: &str,
) -> Result<Vec<String>, config::ConfigError> {
config
.get(key)
.map(|string| vec![string])
.or_else(|_| config.get::<Vec<String>>(key))
}
fn resolve_default_command(
ui: &Ui,
config: &config::Config,
@ -2194,7 +2204,8 @@ fn resolve_default_command(
if let Some(matches) = matches {
if matches.subcommand_name().is_none() {
if config.get_string("ui.default-command").is_err() {
let args = get_string_or_array(config, "ui.default-command");
if args.is_err() {
writeln!(
ui.hint(),
"Hint: Use `jj -h` for a list of available commands."
@ -2204,11 +2215,10 @@ fn resolve_default_command(
"Run `jj config set --user ui.default-command log` to disable this message."
)?;
}
let default_command = config
.get_string("ui.default-command")
.unwrap_or_else(|_| "log".to_string());
let default_command = args.unwrap_or_else(|_| vec!["log".to_string()]);
// Insert the default command directly after the path to the binary.
string_args.insert(1, default_command);
string_args.splice(1..1, default_command);
}
}
Ok(string_args)

View file

@ -44,7 +44,18 @@
"default-command": {
"type": "string",
"description": "Default command to run when no explicit command is given",
"default": "log"
"default": "log",
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
},
"default-description": {
"type": "string",

View file

@ -101,6 +101,17 @@ fn test_no_subcommand() {
(empty) (no description set)
~
"###);
// Multiple default command strings work.
test_env.add_config(r#"ui.default-command=["commit", "-m", "foo"]"#);
test_env.jj_cmd_ok(&repo_path, &["new"]);
std::fs::write(repo_path.join("file.txt"), "file").unwrap();
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &[]);
assert_eq!(stdout, "");
insta::assert_snapshot!(stderr, @r###"
Working copy now at: kxryzmor 70ac3df3 (empty) (no description set)
Parent commit : lylxulpl 9dbbb452 foo
"###);
}
#[test]