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

Custom configuration file path #49

Open
woosaaahh opened this issue May 27, 2023 · 4 comments
Open

Custom configuration file path #49

woosaaahh opened this issue May 27, 2023 · 4 comments

Comments

@woosaaahh
Copy link

woosaaahh commented May 27, 2023

Hi !

First, thanks a lot for this amazing project !!!
I just started to use it today and it does everything I need.
The tool is very easy to configure and easy to use.

However, I miss one thing : using a custom location for the configuration file.
I might have missed something but specifying a custom location with --config=<custom_path>/precious.toml,
only allows using 'precious' on files that have <custom_path> as directory ancestor.


Example :

Let say the current directory is $HOME/code/python/foobar

This command fails

precious --config="$HOME/.config/precious/precious.toml" tidy --label=python file.py
[precious_core::precious][ERROR] Failed to run precious: The path "/home/<user>/code/python/foobar/file.py" does not contain "/home/<user>/.config/precious" as a prefix

but this one works
precious --config="$HOME/precious.toml" tidy --label=python file.py


For modern tools, I'm really not a fan of having config files at the root of my 'home' directory.

I'm also not a fan of having to use a config file in every project directories because I would have to duplicate the config file a lot.
If I modify one 'precious' config file in a project, I would have to update all other config files.

Using one central config file would also allows me to configure my IDE or text editor to use 'precious' for every file independently of their locations.


Is there is a way to not force "same ancestor" location, please ?

Maybe by supporting environment variables or "well-known" locations like the following ?

  • $XDG_CONFIG_DIR/precious/precious.toml
  • $XDG_CONFIG_DIR/precious.toml
  • %APPDATA\precious\precious.toml
  • ...

Thanks a lot again for this project !

@autarch
Copy link
Member

autarch commented May 28, 2023

I tend to think of this as a per-project tool, but I'm okay with a PR to look in those well-known locations. It looks like https://lib.rs/crates/directories is the right crate to use for this.

@woosaaahh
Copy link
Author

Everytime I tried to do some coding in Rust, I had hard times.
I don't know if I'll do the PR but at least not this week.

@autarch
Copy link
Member

autarch commented Jul 1, 2023

Looking at the code, it occurs to me that to really make this work might also require adding a new --project-root CLI param as well. That's because even if I made precious look for the config file elsewhere, the current logic for resolving the project root depends on the config file living in the project itself.

Another option would be to look for a VCS directory like .git or .hg to find the project root.

@autarch
Copy link
Member

autarch commented Jul 3, 2023

Another option would be to look for a VCS directory like .git or .hg to find the project root.

Apparently I don't know how my own code works. It already does this. So I think looking for the config file outside the current dir and its parents should just work as long as precious is executed somewhere inside a VCS working dir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants