cli icon indicating copy to clipboard operation
cli copied to clipboard

Make it possible to read the configuration file from the current directory

Open OsmanMElsayed opened this issue 1 year ago • 7 comments

Describe the problem you'd like to have solved

Currently, the CLI supports reading the .fga.yaml config file by default from:

  • The home dir
  • Or, under fga/.fga.yaml in the user config dir

As a developer, I would like to have the .fga.yaml file on the root folder of my repo, so that I can easily find it and edit it without leaving the IDE and without the need to supply the --config param everytime I user the CLI.

Describe the ideal solution

If the CLI can also, on top of the directories mentioned above, read the .fga.yaml file from the working directory, that would be a nice improvement to the DevEx.

OsmanMElsayed avatar Mar 28 '25 13:03 OsmanMElsayed

@OsmanMElsayed thanks for the feedback!

@rhamzeh I think this make sense, wdyt?

aaguiarz avatar Mar 28 '25 13:03 aaguiarz

Thanks for the suggestion @OsmanMElsayed - yeah I also agree this would be good to have!

rhamzeh avatar Mar 29 '25 12:03 rhamzeh

Awesome! Thank you folks for the fast response on this issue and bulding and maintaing this awesome product <3

I'd be happy to send a PR your way, if that's fine by you! As far as I can see it should be as simple as adding a one-liner (viper.AddConfigPath(".")) to these paths.

IMO it's more logical to add it to the top, so it takes precedence over other config files in the home directory and whatnot, but then again, that constitutes a behavioral breaking change, wdyt @rhamzeh?

OsmanMElsayed avatar Mar 29 '25 12:03 OsmanMElsayed

My main concern here is that we might would be further away from the XDG Base Directory. And I'm not sure if there's any other unix cli tools that load from the current directory first (do you have any examples?).

That said, I do think this would be useful to folks using the FGA CLI, but just generally concerned that it is now different from the majority of the unix CLI commands.

Long term, I think we should be overhauling our config to be something similar to what k8s CLI does.

$XDG_CONFIG_HOME/
  fga/
    default/
      fga.config.yaml
    localhost/
      fga.config.yaml
    localhost-store1/
      fga.config.yaml
    remote-store1/
      fga.config.yaml

allow users to switch with:

fga set-config-ctx default

or something along those lines

I'll loop in @senojj in case he has any ideas.

rhamzeh avatar Apr 21 '25 13:04 rhamzeh

@OsmanMElsayed - folks correctly pointed out that git already does this as an example.

A suggestion came in that we recursively traverse directories until we reach the home dir looking for a .fga directory. I like that, but for the scope of this issue, I think your suggestion would be enough and we can tackle the traversal in a separate issue. WDYT?

rhamzeh avatar Apr 23 '25 14:04 rhamzeh

Thank you for the input!

The recursive traversal makes a lot of sense 👍, and yes, let's tackle it in a separate issue (I will leave that to you guys as my go skills aren't that sharp :D).

Cool! I will create a PR soon-ish, with my suggestion.

OsmanMElsayed avatar Apr 26 '25 23:04 OsmanMElsayed

Hi @OsmanMElsayed, I will assign this one to you. Thanks!

dyeam0 avatar May 09 '25 18:05 dyeam0