Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to include directories as an extension of the config file #421

Merged
merged 20 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2e0e9ba
Add the ability to have the config file in $XDG_CONFIG_HOME/topgrade/…
PolpOnline May 3, 2023
3842ab6
Added ability to include directories as an extension of the config file
PolpOnline May 4, 2023
e8a77e2
Removed useless dependency "serde_json"
PolpOnline May 4, 2023
a02cdd2
Merge branch 'topgrade-rs:master' into master
PolpOnline May 4, 2023
7f2a57c
fmt
PolpOnline May 4, 2023
a3c7b64
Merge remote-tracking branch 'origin/master'
PolpOnline May 4, 2023
e895bbb
Implemented merge strategy for the Commands type
PolpOnline May 5, 2023
aaf71f7
Merge branch 'master' into master
PolpOnline May 5, 2023
5b387b5
Do not stop loading included files if these are invalid/can't be load…
PolpOnline May 5, 2023
daae5d9
Merge branch 'master' into master
PolpOnline May 16, 2023
84ab841
Process includes in the order they are declared. Move all global scop…
PolpOnline May 24, 2023
8753736
remove unused import
PolpOnline May 24, 2023
afe9e9b
Auto-migrate configs without [misc]
PolpOnline May 24, 2023
ab6987a
Merge branch 'master' into master
PolpOnline May 24, 2023
07d3919
Update config.example.toml to reflect changes made to the code
PolpOnline May 24, 2023
ef33500
Merge remote-tracking branch 'origin/master'
PolpOnline May 24, 2023
33d1fc6
Read all files in $CONFIG_DIR/topgrade/topgrade.d/ as part of the con…
PolpOnline May 24, 2023
b514dfd
Merge branch 'master' into master
s34m May 25, 2023
2c45801
Refactor PR code, fmt
PolpOnline May 25, 2023
c232541
Merge branch 'master' into master
PolpOnline May 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ shell-words = "~1.1"
color-eyre = "~0.6"
tracing = { version = "~0.1", features = ["attributes", "log"] }
tracing-subscriber = { version = "~0.3", features = ["env-filter", "time"] }
merge = "0.1.0"

[target.'cfg(target_os = "macos")'.dependencies]
notify-rust = "~4.5"
Expand Down
5 changes: 5 additions & 0 deletions config.example.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Include any additional configuration file(s)
# Note that this config file overrides the includes
# and includes that are on the left override the ones on the right in this array
Copy link
Contributor

@openjck openjck May 6, 2023

Choose a reason for hiding this comment

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

Thanks for your interest in this issue.

This part caught my attention. If consistency with other tools is important, it might be good to look at how other tools handle this. It's my understanding that Git, Vim, Bash, and others don't have the main configuration file take precedence. Instead, settings at the bottom of those configuration files take precedence over settings at the tops of those files, and included files are treated as though their contents are inlined.

For example, with the following setup, the effective email address would be included@example.com:

// .gitconfig
[user]
  email = main@example.com

[include]
  path = .gitconfig.included
// .gitconfig.included
[user]
  email = included@example.com

However, if the include is moved up, the effective email address would be main@example.com:

// .gitconfig
[include]
  path = .gitconfig.included

[user]
  email = main@example.com
// .gitconfig.included
[user]
  email = included@example.com

As far as I know, the same principle is true for Bash, Vim, and others. Settings at the bottom override settings at the top, and included files are treated as if their contents exist at the location of the include.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This can't be done, not without a breaking change in the way the misc config entries are handled.
This is because as of now these entries are handled in the global scope, and adding an [include] section in between these breaks the following ones, because there is currently no way to specify a return to global scope in TOML files.

The simplest way to fix this is to add a section named [misc] and move all the currently-in-global-scope entries to it.
The problem with this approach is that it breaks all the previously-created config files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DottoDev since you are the maintainer of this repository, I'm asking you to tell me how to proceed.

If we are going to migrate all currently-in-global-scope entries to the new [misc] section, I'm available to adapt topgrade to auto migrate the config file.

Copy link
Member

Choose a reason for hiding this comment

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

If config files can be auto migrated it would be a good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've just pushed a commit to resolve this. I've already tested it myself, but you might want to check it out too @openjck.

#include = ["/etc/topgrade.toml"]
PolpOnline marked this conversation as resolved.
Show resolved Hide resolved

# Don't ask for confirmations
#assume_yes = true

Expand Down