hakoerber / git-repo-manager

A git tool to manage worktrees and integrate with GitHub and GitLab
https://hakoerber.github.io/git-repo-manager/
GNU General Public License v3.0
62 stars 9 forks source link

feature request: config file fallback paths #71

Open montchr opened 2 months ago

montchr commented 2 months ago

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 commented 2 months ago

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:

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: https://github.com/hakoerber/git-repo-manager/blob/3a433a1acdf99e4f0bd7e6726ea6a2814f82b26d/src/grm/cmd.rs#L176

The configuration file itself is read here: https://github.com/hakoerber/git-repo-manager/blob/3a433a1acdf99e4f0bd7e6726ea6a2814f82b26d/src/grm/main.rs#L27

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).