Skip to content

Commit

Permalink
Add submitContext constructor & move validation
Browse files Browse the repository at this point in the history
  • Loading branch information
jdsutherland committed Jan 2, 2019
1 parent 57f384d commit c296db4
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions cmd/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ var submitCmd = &cobra.Command{
}

type submitContext struct {
args []string
usrCfg *viper.Viper
args []string
}

func runSubmit(cfg config.Config, flags *pflag.FlagSet, args []string) error {
Expand Down Expand Up @@ -99,14 +99,18 @@ func runSubmit(cfg config.Config, flags *pflag.FlagSet, args []string) error {
return nil
}

func (s *submitContext) validateUserConfig() error {
if s.usrCfg.GetString("token") == "" {
return fmt.Errorf(msgWelcomePleaseConfigure, config.SettingsURL(s.usrCfg.GetString("apibaseurl")), BinaryName)
func newSubmitContext(usrCfg *viper.Viper, args []string) (*submitContext, error) {
if usrCfg.GetString("token") == "" {
return nil, fmt.Errorf(
msgWelcomePleaseConfigure,
config.SettingsURL(usrCfg.GetString("apibaseurl")),
BinaryName,
)
}
if s.usrCfg.GetString("workspace") == "" {
return fmt.Errorf(msgRerunConfigure, BinaryName)
if usrCfg.GetString("workspace") == "" {
return nil, fmt.Errorf(msgRerunConfigure, BinaryName)
}
return nil
return &submitContext{args: args, usrCfg: usrCfg}, nil
}

func (s *submitContext) sanitizeArgs() error {
Expand Down

0 comments on commit c296db4

Please sign in to comment.