Skip to content

Merge entries within the 'commands' config#29

Merged
dzfrias merged 1 commit intodzfrias:mainfrom
warpfork:merge-commands-across-config-files
Sep 29, 2023
Merged

Merge entries within the 'commands' config#29
dzfrias merged 1 commit intodzfrias:mainfrom
warpfork:merge-commands-across-config-files

Conversation

@warpfork
Copy link
Copy Markdown
Contributor

Merge entries in the 'commands' config when loading multiple files (rather than replacing it / dropping existing entries).

With this change, if you have a ~/.config/projectable/config.toml file that contains...

[commands]
"ctrl-t" = "echo hey there"
"ctrl-y" = "echo this is a demo"

and then a $PWD/.projectable.toml file that contains...

[commands]
"ctrl-t" = "echo this is replaced"
"ctrl-u" = "echo this is another command"

Then when you run prj in that $PWD (or below), you'll get three commands: one for ctrl-t, one for ctrl-y, and one for ctrl-u. The command bound to ctrl-t will be the one that in this example says "replaced".

Previously, the whole command map was getting replaced, which meant in this scenario you'd only end up with ctrl-t and ctrl-u (the ctrl-y command from the parent config just got discarded).

I suppose this could be considered a breaking change, but for me, it's what I expected when I first read the docs about the built-in configuration merging, so hopefully it's inline with the intentions of the project :)

…tiple config files.

With this change, if you have a `~/.config/projectable/config.toml` file that contains...

```
[commands]
"ctrl-t" = "echo hey there"
"ctrl-y" = "echo this is a demo"
```

and then a `$PWD/.projectable.toml` file that contains...

```
[commands]
"ctrl-t" = "echo this is replaced"
"ctrl-u" = "echo this is another command"
```

Then when you run `prj` in that `$PWD` (or below), you'll get three commands:
one for `ctrl-t`, one for `ctrl-y`, and one for `ctrl-u`.
The command bound to `ctrl-t` will be the one that in this example says "replaced".

Previously, the whole command map was getting replaced,
which meant in this scenario you'd only end up with `ctrl-t` and `ctrl-u`
(the `ctrl-y` command from the parent config just got discarded).

I suppose this could be considered a breaking change, but for me,
it's what I expected when I first read the docs about the built-in
configuration merging, so hopefully it's not too spicy :)
@warpfork
Copy link
Copy Markdown
Contributor Author

(It's a very tiny diff, because all that was needed is to switch to using the HashMap merge function instead of the merge macro that only looks at the whole value non-recursively.)

@dzfrias
Copy link
Copy Markdown
Owner

dzfrias commented Sep 29, 2023

Thanks for the PR! Yeah, I'd definitely say that this behavior makes more sense when looking at config merging as a whole.

@dzfrias dzfrias merged commit cd26095 into dzfrias:main Sep 29, 2023
@warpfork warpfork deleted the merge-commands-across-config-files branch September 29, 2023 21:28
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