Skip to content

Commit 05096a3

Browse files
jdsutherlandKatrina Owen
authored andcommitted
Extract common validate user config helper method
This logic occurs in several of the commands.
1 parent c39243d commit 05096a3

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

cmd/cmd.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package cmd
22

3+
import (
4+
"fmt"
5+
6+
"github.com/exercism/cli/config"
7+
"github.com/spf13/viper"
8+
)
9+
310
const msgWelcomePleaseConfigure = `
411
512
Welcome to Exercism!
@@ -33,3 +40,18 @@ const msgMissingMetadata = `
3340
Please see https://exercism.io/cli-v1-to-v2 for instructions on how to fix it.
3441
3542
`
43+
44+
// validateUserConfig validates the presense of required user config values
45+
func validateUserConfig(cfg *viper.Viper) error {
46+
if cfg.GetString("token") == "" {
47+
return fmt.Errorf(
48+
msgWelcomePleaseConfigure,
49+
config.SettingsURL(cfg.GetString("apibaseurl")),
50+
BinaryName,
51+
)
52+
}
53+
if cfg.GetString("workspace") == "" || cfg.GetString("apibaseurl") == "" {
54+
return fmt.Errorf(msgRerunConfigure, BinaryName)
55+
}
56+
return nil
57+
}

0 commit comments

Comments
 (0)