Skip to content

Commit

Permalink
Adjust Viper config file parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
camerondurham committed May 28, 2021
1 parent 66dae7d commit a97fccd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
8 changes: 6 additions & 2 deletions cmd/util/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit a97fccd

Please sign in to comment.