Simple test of getting environment variables with viper (golang)
Nothing much to see here - just a sanity check during some debugging. What happened? viper is how I get environment variables into CLI in support of a 12-factor approach. Adding cobra subcommands seemed to break this. So I wrote this sanity-checker to isolate the issue. It boiled down to the order in which the multiple init functions were being called. It was more straightfoward to just move the viper calls into the command functions, which is consistent with the environemnt variables being re-read on each viper.Get.
Set these two environment variables, e.g
export ROOTCMD_TEST=bar
export SUBCMD_TEST=pong
------------RESULTS--------------------
main()::viper.Get("test") = bar
main()::go func()::viper.Get("test") = bar
main()::func()::viper.Get("test") = bar
main()::func()::viper.SetEnvPrefix("SUBCMD")
main()::func()::viper.Get("test") = pong