Skip to content

Commit df788ea

Browse files
committed
cli --config global option: allow spaces around =
This is especially useful for complicated options like ``` --config 'revsets."immutable_heads()" = "none()"' ```
1 parent 6327cc1 commit df788ea

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
8989
reversing colors rather than underlining, you can set
9090
`colors."diff token"={ underline = false, reverse = true }` in your config.
9191

92+
* The `--config` global option now allows whitespace around the equals sign, e.g.
93+
`--config 'revsets."immutable_heads()" = "none()"'` is now legal.
94+
9295
### Fixed bugs
9396

9497
* `jj log -p --stat` now shows diff stats as well as the default color-words/git

cli/src/config.rs

+20-5
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,9 @@ fn parse_config_arg_item(item_str: &str) -> Result<(ConfigNamePathBuf, ConfigVal
579579
let split_candidates = item_str.as_bytes().iter().positions(|&b| b == b'=');
580580
let Some((name, value_str)) = split_candidates
581581
.map(|p| (&item_str[..p], &item_str[p + 1..]))
582-
.map(|(name, value)| name.parse().map(|name| (name, value)))
582+
// Trim spaces, similarly to TOML syntax; names or values with spaces would have to be
583+
// specified with quotes.
584+
.map(|(name, value)| name.trim().parse().map(|name| (name, value.trim())))
583585
.find_or_last(Result::is_ok)
584586
.transpose()
585587
.map_err(|err| config_error_with_message("--config name cannot be parsed", err))?
@@ -827,21 +829,34 @@ mod tests {
827829
assert!(parse_config_arg_item("").is_err());
828830
assert!(parse_config_arg_item("a").is_err());
829831
assert!(parse_config_arg_item("=").is_err());
830-
// The value parser is sensitive to leading whitespaces, which seems
831-
// good because the parsing falls back to a bare string.
832-
assert!(parse_config_arg_item("a = 'b'").is_err());
833832

834833
let (name, value) = parse_config_arg_item("a=b").unwrap();
835834
assert_eq!(name, ConfigNamePathBuf::from_iter(["a"]));
836835
assert_eq!(value.as_str(), Some("b"));
837836

837+
let (name, value) = parse_config_arg_item("a = b").unwrap();
838+
assert_eq!(name, ConfigNamePathBuf::from_iter(["a"]));
839+
assert_eq!(value.as_str(), Some("b"));
840+
841+
let (name, value) = parse_config_arg_item("a = 'b'").unwrap();
842+
assert_eq!(name, ConfigNamePathBuf::from_iter(["a"]));
843+
assert_eq!(value.as_str(), Some("b"));
844+
845+
let (name, value) =
846+
parse_config_arg_item(r#"revsets."immutable_heads()" = "none()""#).unwrap();
847+
assert_eq!(
848+
name,
849+
ConfigNamePathBuf::from_iter(["revsets", "immutable_heads()"])
850+
);
851+
assert_eq!(value.as_str(), Some("none()"));
852+
838853
let (name, value) = parse_config_arg_item("a=").unwrap();
839854
assert_eq!(name, ConfigNamePathBuf::from_iter(["a"]));
840855
assert_eq!(value.as_str(), Some(""));
841856

842857
let (name, value) = parse_config_arg_item("a= ").unwrap();
843858
assert_eq!(name, ConfigNamePathBuf::from_iter(["a"]));
844-
assert_eq!(value.as_str(), Some(" "));
859+
assert_eq!(value.as_str(), Some(""));
845860

846861
// This one is a bit cryptic, but b=c can be a bare string.
847862
let (name, value) = parse_config_arg_item("a=b=c").unwrap();

cli/tests/test_global_opts.rs

+8
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,14 @@ fn test_color_config() {
462462
[EOF]
463463
");
464464

465+
// Spaces around the = signs or dots are OK, by analogy with TOML
466+
let output = work_dir.run_jj(["--config= ui . color = never", "log", "-T", "commit_id"]);
467+
insta::assert_snapshot!(output, @r"
468+
@ 230dd059e1b059aefc0da06a2e5a7dbf22362f22
469+
◆ 0000000000000000000000000000000000000000
470+
[EOF]
471+
");
472+
465473
// --color overrides --config 'ui.color=...'.
466474
let output = work_dir.run_jj([
467475
"--color",

docs/config.md

-1
Original file line numberDiff line numberDiff line change
@@ -1573,7 +1573,6 @@ to specify additional configuration settings. This overrides settings defined in
15731573
config files or environment variables. For example,
15741574

15751575
```shell
1576-
# Must not have spaces around the `=`
15771576
jj --config ui.color=always --config ui.diff-editor=meld split
15781577
```
15791578

0 commit comments

Comments
 (0)