Skip to content

Add XDG Support to confy #119

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

deg4uss3r
Copy link
Contributor

@deg4uss3r deg4uss3r commented May 25, 2025

This PR:

  • Removes the directories crate in favor of etcetera
  • Bumps the project to version 2.0.0
  • Moves config creation and reading to only use $XDG_CONFIG_HOME via etcetera AppStrategy rules
  • Some updated rustfmt from version 1.88

Resolves #117

@deg4uss3r deg4uss3r requested a review from matthiasbeyer May 25, 2025 18:50
@strega-nil
Copy link

I'll take a look at this tomorrow! Thanks for the PR.

Copy link

@strega-nil strega-nil left a comment

Choose a reason for hiding this comment

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

Additionally, I'm really uncomfortable with the idea that one would have a silent, seriously breaking change behind a flag that could get accidentally turned on by a dependency. It would be nice if we checked for both locations on macOS, and maybe had a way to select which method should be used by the downstream application (since, for example, GUI apps may want to put their non-user-editable configuration into ~/Library)

@deg4uss3r deg4uss3r requested a review from Zykino July 23, 2025 01:02
Copy link
Contributor

@Zykino Zykino left a comment

Choose a reason for hiding this comment

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

I don’t really know how to review the code here. I don’t know the directory, even less etcetera crate. 😅 (Also a lot is happening IRL for me so, don’t block on me please :) )

@@ -11,12 +11,12 @@ edition = "2024"

[dependencies]
ron = { version = "0.10.1", optional = true }
directories = "6"
etcetera = "0.10.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a link to https://docs.rs/etcetera/latest/etcetera/#native-strategy (or the discussion we had here) to let peoples know how to configure confy? At least some documentation (or example/test) around it to show can be useful.

@@ -1,6 +1,6 @@
[package]
name = "confy"
version = "1.0.0"
version = "2.0.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

I’m not sure we have a change-log file, but writing somewhere what made change the major version can help peoples migrate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

100% once we work out the API I am going to add into here: https://github.com/rust-cli/confy/?tab=readme-ov-file#breaking-changes

Comment on lines +490 to +491
fn get_configuration_directory_str(project: &impl AppStrategy) -> Result<String, ConfyError> {
Ok(project.config_dir().display().to_string())
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
fn get_configuration_directory_str(project: &impl AppStrategy) -> Result<String, ConfyError> {
Ok(project.config_dir().display().to_string())
fn get_configuration_directory_str(project: &impl AppStrategy) -> Result<PathBuf, ConfyError> {
Ok(project.config_dir())

I know it is a private function, but maybe it is better to use the PathBuf directly instead of relying on the String approximation?
Especially since you want to do a major version.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I think the function is used only once… it was a nice helper but may be useless now?

@@ -469,23 +469,26 @@ pub fn get_configuration_file_path<'a>(
config_name: impl Into<Option<&'a str>>,
) -> Result<PathBuf, ConfyError> {
let config_name = config_name.into().unwrap_or("default-config");
let project = ProjectDirs::from("rs", "", app_name).ok_or_else(|| {
ConfyError::BadConfigDirectory("could not determine home directory path".to_string())
let project = choose_app_strategy(AppStrategyArgs {
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I just understand now that you are "forcing" the app strategy? Not configurable then? (Still needs to document this.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I think you're right we should allow this to be configurable for GUI applications, I'll update!

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.

Support XDG directories on macOS
4 participants