You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Config file is being saved on every invocation of the CLI #153
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:
Only creating the directory & config file if it is actually needed, e.g., when calling stackit config set/unset
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.
#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.
Activity
joaopalet commentedon Apr 2, 2024
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 commentedon Apr 5, 2024
Great, thanks for looking into it @joaopalet ❤️
Kumm-Kai commentedon 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.
joaopalet commentedon Apr 8, 2024
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 commentedon Apr 18, 2024
This was addressed in #214 and will be included in the next release.
Thanks @Kumm-Kai for the contribution 💪