Skip to content

Commit

Permalink
Extract common validate user config helper method
Browse files Browse the repository at this point in the history
This logic occurs in several of the commands.
  • Loading branch information
jdsutherland authored and Katrina Owen committed Dec 26, 2018
1 parent c39243d commit 05096a3
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package cmd

import (
"fmt"

"github.com/exercism/cli/config"
"github.com/spf13/viper"
)

const msgWelcomePleaseConfigure = `
Welcome to Exercism!
Expand Down Expand Up @@ -33,3 +40,18 @@ const msgMissingMetadata = `
Please see https://exercism.io/cli-v1-to-v2 for instructions on how to fix it.
`

// validateUserConfig validates the presense of required user config values
func validateUserConfig(cfg *viper.Viper) error {
if cfg.GetString("token") == "" {
return fmt.Errorf(
msgWelcomePleaseConfigure,
config.SettingsURL(cfg.GetString("apibaseurl")),
BinaryName,
)
}
if cfg.GetString("workspace") == "" || cfg.GetString("apibaseurl") == "" {
return fmt.Errorf(msgRerunConfigure, BinaryName)
}
return nil
}

0 comments on commit 05096a3

Please sign in to comment.