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

feature request: config file fallback paths #71

Open
montchr opened this issue May 4, 2024 · 1 comment
Open

feature request: config file fallback paths #71

montchr opened this issue May 4, 2024 · 1 comment

Comments

@montchr
Copy link

montchr commented May 4, 2024

I would like to call grm repos status without needing to specify -c <path> every time I want to use a config file that lives outside the current directory.

This could be done by reading an environment variable when -c is omitted. Something like $GRM_CONFIG_FILE, maybe. It would also be great if grm looked in a standard default location like $XDG_CONFIG_HOME/grm/config.toml.

These would, of course, be overridden if -c <path> was specified. Not sure what the behavior should be if the current directory has a config.toml, but that's a pretty generic filename so perhaps it should be ignored.

@hakoerber
Copy link
Owner

Hey!

Short background about the current implementation: The reason why there is no default repository config is that one may have multiple independent repository configuration for different purposes. I, for example, have one for personal projects on Github, one for work, and one for some random projects I have laying around. This could be done in a single file with multiple trees, but I like to keep things separated.

But I see the appeal of having a single file containing all repo configuration, thank you for bringing up that use case. Thoughts about the implemenatation:

  • The naming of config.toml was a little unfortunate in hindsight. The naming kinda clashes with the worktree-specific grm.toml file that configures grm worktree behaviour. So if we change this, I'd go with "repo config" instead of "config". So:
    • GRM_REPO_CONFIG_FILE
    • $XDG_CONFIG_HOME/grm/repos.toml
    • Adding --repo-config as an alias for --config to grm repos commands and deprecating --config.
  • I also see that a ./config.toml fallback is quite weird. As you said, this is a generic filename.
  • I am personally not a fan of environment variables for such things, but GRM_REPO_CONFIG_FILE would be fine.
  • Never look up such a file in the current working directory, as this may lead to all sorts of unexpected behaviour. Especially because I cannot think of a use case where it makes sense for grm repos to be directory-dependent.

I think the smallest change that would fit your use case would be the $XDG_CONFIG_HOME/grm/repos.toml fallback, keeping the ./config.toml fallback for now. So the lookup order would be (using the first one found):

  1. --config command line parameter
  2. ./config.toml
  3. $XDG_CONFIG_HOME/grm/repos.toml

The fallback is currently implemented as a simple default value for --config in clap:

default_value = "./config.toml",

The configuration file itself is read here:

let config = match config::read_config(&args.config) {

Changing the command line parameter to an Option<String> and doing the fallback processing inside main() (second link) should do the trick. I might not have time do tackle this in the near future, so if you want, feel free to take a stab at this. I would then add a few tests (the test suite is quite ... special).

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

No branches or pull requests

2 participants