Skip to content

Commit 286668a

Browse files
authored
Add XDG Support to confy (#119)
* Remove directories crate for dirs and introduce xdg feature to allow configs to be stored in xdg defaults * Remove feature gates and full move to XDG and etcetera * Add a way to change the stragey by a function call * Add a change strategy example * Document functions and remove helper function that's only used once. Finally move the CI to use a single thread as the changing of the strategy is based on atomics and can fail if multiple threads are changing it at once
1 parent a41f72d commit 286668a

File tree

5 files changed

+302
-32
lines changed

5 files changed

+302
-32
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}-${{ matrix.rust }}
7676

7777
- name: Run cargo test
78-
run: cargo test
78+
run: cargo test -- --test-threads=1
7979
shell: bash
8080

8181
clippy:

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "confy"
3-
version = "1.0.0"
3+
version = "2.0.0"
44
authors = ["Katharina Fey <[email protected]>"]
55
description = "Boilerplate-free configuration management"
66
license = "MIT/X11 OR Apache-2.0"
@@ -11,12 +11,13 @@ edition = "2024"
1111

1212
[dependencies]
1313
ron = { version = "0.10.1", optional = true }
14-
directories = "6"
14+
etcetera = "0.10.0"
1515
serde = "^1.0"
1616
serde_yaml = { version = "0.9", optional = true }
1717
thiserror = "2.0"
1818
basic-toml = { version = "0.1.10", optional = true }
19-
toml = { version = "0.8", optional = true }
19+
toml = { version = "0.9", optional = true }
20+
lazy_static = "1.5"
2021

2122
[features]
2223
default = ["toml_conf"]

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,36 @@ Information about adding context to error messages can be found at [Providing Co
6161

6262
## Config File Location
6363

64-
`confy` uses [ProjectDirs](https://github.com/dirs-dev/directories-rs?tab=readme-ov-file#projectdirs) to store your configuration files, the common locations for those are in the `config_dir` section, below are the common OS paths:
64+
`confy` uses the [etcetera](https://docs.rs/etcetera/latest/etcetera/) crate to store your configuration files, the common locations for those depend on the stratgey usd [`App Strategy`](https://docs.rs/etcetera/latest/etcetera/#appstrategy) or [`Native Strategy`](https://docs.rs/etcetera/latest/etcetera/#native-strategy), below are the common OS paths, you can change the strategy using the built-in [`change_config_strategy`](https://docs.rs/confy/2.0.0/confy/fn.change_config_strategy.html) function.
65+
66+
### App Strategy
67+
68+
This is the default strategy in version `2.0.0`+. It uses the `XDG` format on both Linux and MacOS systems.
69+
70+
| Linux | macOS | Windows |
71+
| --- | --- | --- |
72+
| `$XDG_CONFIG_HOME`/`<project_path>` or `$HOME`/.config/`<project_path>` | `$HOME`/.config/`<project_path>` | `{FOLDERID_RoamingAppData}`/`<project_path>`/config |
73+
74+
Where the `<project_path>` will be `$MY_APP_NAME`.
75+
76+
### Native Strategy
77+
78+
You can change to this strategy which is provided for both backwards capability and for GUI applications on macOS which is more traditional and expects this format.
6579

6680
| Linux | macOS | Windows |
6781
| --- | --- | --- |
6882
| `$XDG_CONFIG_HOME`/`<project_path>` or `$HOME`/.config/`<project_path>` | `$HOME`/Library/Application Support/`<project_path>` | `{FOLDERID_RoamingAppData}`/`<project_path>`/config |
6983

70-
Where the `<project_path>` will be `rs.$MY_APP_NAME`.
84+
Where the `<project_path>` will be `rs.$MY_APP_NAME` on macOS and just `$MY_APP_NAME` elsewhere.
7185

7286
## Breaking changes
7387

88+
### Version 2.0.0
89+
90+
In version `2.0.0` we moved from the [`ProjectDirs`](https://github.com/dirs-dev/directories-rs?tab=readme-ov-file#projectdirs) crate to [`etcetera`](https://docs.rs/etcetera/latest/etcetera/) allowing for both uses of `XDG` or the OS's Native paths.
91+
92+
* From now on the default will be using `XDG` directories on macOS.
93+
7494
### Version 0.6.0
7595

7696
In this version we bumped several dependencies which have had changes with some of the default (de)serialization process:

examples/simple.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn main() -> Result<(), confy::ConfyError> {
4141
name: "Test".to_string(),
4242
..cfg
4343
};
44-
confy::store("confy_simple_app",None, &cfg)?;
44+
confy::store("confy_simple_app", None, &cfg)?;
4545
println!("The updated toml file content is:");
4646
let mut content = String::new();
4747
std::fs::File::open(&file)
@@ -53,7 +53,6 @@ fn main() -> Result<(), confy::ConfyError> {
5353
name: "Test".to_string(),
5454
..cfg
5555
};
56-
std::fs::remove_dir_all(file.parent().unwrap())
57-
.expect("Failed to remove directory");
56+
std::fs::remove_dir_all(file.parent().unwrap()).expect("Failed to remove directory");
5857
Ok(())
5958
}

0 commit comments

Comments
 (0)