Skip to content

Config file is being saved on every invocation of the CLI #153

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

Closed
Kumm-Kai opened this issue Mar 12, 2024 · 5 comments
Closed

Config file is being saved on every invocation of the CLI #153

Kumm-Kai opened this issue Mar 12, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@Kumm-Kai
Copy link
Member

Kumm-Kai commented Mar 12, 2024

Currently, the STACKIT CLI calls the config.InitConfig function on every invocation.

On the very first call of the binary (no .stackit directory exists), it creates the directory and a config file (with default values).
On every following binary call the config file is being read and directly written to disk again.

This is probably only problematic in some small edge cases, like calling stackit multiple times in one command using process substiution (e.g., <(stackit xyz)). In this case the CLI fails because viper.WriteConfigAs is not concurrency-safe.

This can be solved by either:

  1. Only creating the directory & config file if it is actually needed, e.g., when calling stackit config set/unset
  2. Only writing the config file when necessary (e.g., file on disk differs from config in memory)

From my point of view the first solution would be the best one because in my opinion there is no need to create a config file if the user didn't change the defaults.

@joaopalet
Copy link
Contributor

Hi @Kumm-Kai,
Thanks for the suggestion! This was addressed in the PR linked above and will be included in the next release.

@Kumm-Kai
Copy link
Member Author

Kumm-Kai commented Apr 5, 2024

Great, thanks for looking into it @joaopalet ❤️

@Kumm-Kai Kumm-Kai closed this as completed Apr 5, 2024
@Kumm-Kai
Copy link
Member Author

Kumm-Kai commented Apr 6, 2024

#185 doesn't completely solve this issue. A empty file is still being created on the very first invocation.
This still results in failures when using process substiution.
I would propose only creating the file and directory if something should actually be written.

If you want to I can open a PR for it.

@Kumm-Kai Kumm-Kai reopened this Apr 6, 2024
@joaopalet
Copy link
Contributor

Ah good point, I though the issue was only in viper.WriteConfigAs.

If you want to raise the PR making the fix I would be happy to review and support, otherwise I will try to do it within the next few days.

@joaopalet
Copy link
Contributor

This was addressed in #214 and will be included in the next release.

Thanks @Kumm-Kai for the contribution 💪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants