Closed
Description
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.