Edit config files with a temp editor and add some validation #3945
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #3905
This solves a problem where
jj config edit
drops you straight into an editor and allows you to save an invalid toml file. If you mess up your toml syntax, jj cannot launch (evenjj config edit
!)This implements a pattern I've seen in tools like
crontab -e
orvisudo
where you get dropped into a temporary file editor and the tool does a bit of sanity checking before copying over the contents of the temporary file into the actual file.Code wise: this reuses a utility function which takes care of the heavy lifting for creating a temporary file and launching an editor. I put all the validation in a new function in cli/src/config.rs, which seemed a bit like overkill but I figured the details of the config format being toml shouldn't leak into cli_util or command/config
Checklist
If applicable:
CHANGELOG.md