forked from mirrors/jj
cli_util: support multiple cli arguments for ui.default-command
This commit is contained in:
parent
bf76080f42
commit
b4c4d91190
4 changed files with 41 additions and 6 deletions
|
@ -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
|
defined template names when no argument is given, assisting the user in making
|
||||||
a selection.
|
a selection.
|
||||||
|
|
||||||
|
* `ui.default-command` now accepts multiple string arguments, for more complex
|
||||||
|
default `jj` commands.
|
||||||
|
|
||||||
### Fixed bugs
|
### Fixed bugs
|
||||||
|
|
||||||
* On Windows, symlinks in the repo are now supported when Developer Mode is enabled.
|
* On Windows, symlinks in the repo are now supported when Developer Mode is enabled.
|
||||||
|
|
|
@ -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(
|
fn resolve_default_command(
|
||||||
ui: &Ui,
|
ui: &Ui,
|
||||||
config: &config::Config,
|
config: &config::Config,
|
||||||
|
@ -2194,7 +2204,8 @@ fn resolve_default_command(
|
||||||
|
|
||||||
if let Some(matches) = matches {
|
if let Some(matches) = matches {
|
||||||
if matches.subcommand_name().is_none() {
|
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!(
|
writeln!(
|
||||||
ui.hint(),
|
ui.hint(),
|
||||||
"Hint: Use `jj -h` for a list of available commands."
|
"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."
|
"Run `jj config set --user ui.default-command log` to disable this message."
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
let default_command = config
|
let default_command = args.unwrap_or_else(|_| vec!["log".to_string()]);
|
||||||
.get_string("ui.default-command")
|
|
||||||
.unwrap_or_else(|_| "log".to_string());
|
|
||||||
// Insert the default command directly after the path to the binary.
|
// 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)
|
Ok(string_args)
|
||||||
|
|
|
@ -44,7 +44,18 @@
|
||||||
"default-command": {
|
"default-command": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Default command to run when no explicit command is given",
|
"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": {
|
"default-description": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
|
|
@ -101,6 +101,17 @@ fn test_no_subcommand() {
|
||||||
│ (empty) (no description set)
|
│ (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]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue