codenotary / immudb

immudb - immutable database based on zero trust, SQL/Key-Value/Document model, tamperproof, data change history
https://immudb.io
Other
8.54k stars 340 forks source link

Remove config initialization from init() #336

Closed padurean closed 4 years ago

padurean commented 4 years ago

What happened helper.InitConfig gets called also for commands other than the currently running one.

What you expected to happen helper.InitConfig gets called only for the currently running command.

How to reproduce it (as minimally and precisely as possible) Add a println in the definition of helper.InitConfig and run any CLI - e.g. immuadmin. Observe that InitConfig gets called for other commands too - output example:

./immuadmin user list
~~~~~> config name immudb
Using config file: /Users/ogg/ws/github/immudb/configs/immudb.toml
~~~~~> config name immugw
~~~~~> config name immuadmin

Environment

./immuadmin version
Using config file: /Users/ogg/ws/github/immudb/configs/immudb.toml
immuadmin v0.6.1
Commit  : 611dbde030a198671081459550323dfc008078d5
Built by: 912518+padurean@users.noreply.github.com
Built at: Wed, 10 Jun 2020 20:12:30 EEST

Additional info (any other context about the problem) Initialisation code like this should be moved (for all CLIs) from init to NewCmd

func init() {
    cobra.OnInitialize(func() { o.InitConfig("immudb") })
}
mmeloni commented 4 years ago

fixed at https://github.com/codenotary/immudb/commit/83f0b3b09d6792ab012f0c8e12d7a2d45e813ab6