Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
* `jj util exec` now matches the exit status of the program it runs, and
doesn't print anything.

* `jj config get` now supports displaying array and table config values.

### Fixed bugs

* Fetching repositories that have submodules no longer errors even if
Expand Down
30 changes: 12 additions & 18 deletions cli/src/commands/config/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,18 @@ pub fn cmd_config_get(
command: &CommandHelper,
args: &ConfigGetArgs,
) -> Result<(), CommandError> {
let stringified = command
.settings()
.get_value_with(&args.name, |value| match value {
// Remove extra formatting from a string value
ConfigValue::String(v) => Ok(v.into_value()),
// Print other values in TOML syntax (but whitespace trimmed)
ConfigValue::Integer(_)
| ConfigValue::Float(_)
| ConfigValue::Boolean(_)
| ConfigValue::Datetime(_) => Ok(value.decorated("", "").to_string()),
// TODO: maybe okay to just print array or table in TOML syntax?
ConfigValue::Array(_) => {
Err("Expected a value convertible to a string, but is an array")
}
ConfigValue::InlineTable(_) => {
Err("Expected a value convertible to a string, but is a table")
}
})?;
let value = command.settings().get_value(&args.name)?;
let stringified = match value {
// Remove extra formatting from a string value
ConfigValue::String(v) => v.into_value(),
// Print other values in TOML syntax (but whitespace trimmed)
ConfigValue::Integer(_)
| ConfigValue::Float(_)
| ConfigValue::Boolean(_)
| ConfigValue::Datetime(_)
| ConfigValue::Array(_)
| ConfigValue::InlineTable(_) => value.decorated("", "").to_string(),
};
writeln!(ui.stdout(), "{stringified}")?;
Ok(())
}
22 changes: 6 additions & 16 deletions cli/tests/test_config_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1252,26 +1252,16 @@ fn test_config_get() {
");

let output = test_env.run_jj_in(".", ["config", "get", "table.list"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Config error: Invalid type or value for table.list
Caused by: Expected a value convertible to a string, but is an array
Hint: Check the config file: $TEST_ENV/config/config0002.toml
For help, see https://jj-vcs.github.io/jj/latest/config/ or use `jj help -k config`.
insta::assert_snapshot!(output, @r#"
["list", "value"]
[EOF]
[exit status: 1]
");
"#);

let output = test_env.run_jj_in(".", ["config", "get", "table"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Config error: Invalid type or value for table
Caused by: Expected a value convertible to a string, but is a table
Hint: Check the config file: $TEST_ENV/config/config0003.toml
For help, see https://jj-vcs.github.io/jj/latest/config/ or use `jj help -k config`.
insta::assert_snapshot!(output, @r#"
{ string = "some value 1", int = 123, list = ["list", "value"], overridden = "bar" }
[EOF]
[exit status: 1]
");
"#);

let output = test_env.run_jj_in(".", ["config", "get", "table.overridden"]);
insta::assert_snapshot!(output, @r"
Expand Down