From a97fccd06c83cbe1170c71437a2c1ae3d41eb2e3 Mon Sep 17 00:00:00 2001 From: Cameron Durham Date: Fri, 28 May 2021 03:28:51 -0700 Subject: [PATCH] Adjust Viper config file parsing --- cmd/root.go | 6 ++++-- cmd/util/cli.go | 8 ++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index a8d5bbd..27a10c6 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -74,10 +74,12 @@ func optionalVersionCheck() { if err != nil { util.DebugPrint(fmt.Sprintf("error reading environment file: %v", err)) checkLatestVersion() - } else if v, ok := opts["version_check"]; !ok || v == "true" { + } else if v, ok := opts["checkversion"]; !ok || v.CheckVersion { + util.DebugPrint(fmt.Sprintf("checkversion: true or no checkversion option found\n")) checkLatestVersion() } else { - util.DebugPrint(fmt.Sprintf("local package version: %s\nlatest version: %s\n", version.PkgVersion, v)) + util.DebugPrint(fmt.Sprintf("parsed options: %v\n", opts)) + util.DebugPrint(fmt.Sprintf("local package version: %s\nlatest version: %v\n", version.PkgVersion, v)) } } diff --git a/cmd/util/cli.go b/cmd/util/cli.go index 72aa945..562cba6 100644 --- a/cmd/util/cli.go +++ b/cmd/util/cli.go @@ -40,6 +40,10 @@ type ContainerOpts struct { Shell string } +type CliOpts struct { + CheckVersion bool +} + // Cli TODO: add config/env settings to use Cli in other commands type Cli struct { in *streams.In @@ -103,11 +107,11 @@ func GetEnvs() (envs map[string]*ContainerOpts, err error) { } // GetConfigOpts retrieves optional settings from ~/.ch.yaml -func GetConfigOpts() (opts map[string]string, err error) { +func GetConfigOpts() (opts map[string]*CliOpts, err error) { if !viper.IsSet("opts") { return nil, ErrDoesNotExist } - opts = make(map[string]string) + opts = make(map[string]*CliOpts) err = viper.UnmarshalKey("opts", &opts) return }