Skip to content

Conversation

AngelEzquerra
Copy link
Contributor

Up until now, trying to get a config value that was an array or a table would fail with an error indicating that only values that can be converted to a string can be displayed. This change fixes that issue by converting arrays and tables into TOML format.

Checklist

If applicable:

  • [ x] I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
  • I have updated the config schema (cli/src/config-schema.json)
  • [ x] I have added/updated tests to cover my changes

@AngelEzquerra AngelEzquerra requested a review from a team as a code owner August 31, 2025 18:24
@AngelEzquerra AngelEzquerra force-pushed the config_get_complex_values branch from e564d73 to a72d131 Compare August 31, 2025 18:51
| ConfigValue::Boolean(_)
| ConfigValue::Datetime(_)
| ConfigValue::Array(_) => Ok(value.decorated("", "").to_string()),
ConfigValue::InlineTable(v) => Ok(format_inline_table_as_toml(&v)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think inline table should be printed as value. It would be weird if colors.error were flattened, for example. To list non-value table items, the user should use jj config list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by "value". Do you mean printing the table as a JSON object?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, as a TOML inline table.
https://toml.io/en/v1.0.0#inline-table

BTW, we no longer have to use .get_value_with() because it doesn't fail conditionally.

let value = command.settings().get_value(..)?;
if let Some(s) = value.as_str() {
    writeln!(ui.stdout(), "{s}")?;
} else {
    writeln!(ui.stdout(), "{}", value.decorated("", ""))?;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first stab at this printed inline tables "as is" but I found that it was very unreadable, with the table being printed in a single line. Is that what you propose? Or would do you want to somehow pretty print the inline table into multiple lines? I thought it would make more sense to print them as a proper TOML table instead...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, just print it as a TOML inline table. It would be weird if jj config get returned multiple values depending on the type.

Strictly speaking, it's also odd that a string value is printed without quotes, which cannot be parsed as a TOML value. We might have to add -T/--template option to print the value in user-specified format.

Copy link
Contributor Author

@AngelEzquerra AngelEzquerra Sep 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I've changed it so that it just printing inline tables as you suggested.

@AngelEzquerra AngelEzquerra force-pushed the config_get_complex_values branch from a72d131 to e141f39 Compare September 6, 2025 12:16
Up until now, trying to get a config value that was an array or a table would fail with an error indicating that only values that can be converted to a string can be displayed. This change fixes that issue by converting arrays and tables into TOML format.
@AngelEzquerra AngelEzquerra force-pushed the config_get_complex_values branch from e141f39 to 781cb7e Compare September 6, 2025 12:35
Comment on lines +149 to +150
* `jj config get` now supports displaying array and table config values.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: move this to "Unreleased" and remove excessive blank line.

Comment on lines +49 to +53
let stringified =
command
.settings()
.get_value_with(&args.name, |value| -> Result<String, &str> {
match value {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: since inner function no longer fails, we don't have to use .get_value_with().

match command.settings().get_value(&args.name)? {
    ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants