Skip to content

Commit

Permalink
Move sanitizeArgs to constructor
Browse files Browse the repository at this point in the history
sanitizeArgs is more of an implementation detail than a public API, so
it is better encapsulated in the constructor.
  • Loading branch information
jdsutherland committed Jan 2, 2019
1 parent c686c3c commit 2a879b5
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions cmd/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,8 @@ type submitContext struct {
}

func runSubmit(cfg config.Config, flags *pflag.FlagSet, args []string) error {
usrCfg := cfg.UserViperConfig

if err := validateUserConfig(usrCfg); err != nil {
return err
}

ctx := &submitContext{args: args, flags: flags, usrCfg: usrCfg}

if err := ctx.sanitizeArgs(); err != nil {
ctx, err := newSubmitContext(cfg.UserViperConfig, flags, args)
if err != nil {
return err
}

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

func newSubmitContext(usrCfg *viper.Viper, args []string) (*submitContext, error) {
// newSubmitContext creates a submitContext and sanitizes the arguments.
func newSubmitContext(usrCfg *viper.Viper, flags *pflag.FlagSet, args []string) (*submitContext, error) {
if usrCfg.GetString("token") == "" {
return nil, fmt.Errorf(
msgWelcomePleaseConfigure,
Expand All @@ -107,7 +101,9 @@ func newSubmitContext(usrCfg *viper.Viper, args []string) (*submitContext, error
if usrCfg.GetString("workspace") == "" {
return nil, fmt.Errorf(msgRerunConfigure, BinaryName)
}
return &submitContext{args: args, usrCfg: usrCfg}, nil

ctx := &submitContext{usrCfg: usrCfg, flags: flags, args: args}
return ctx, ctx.sanitizeArgs()
}

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

0 comments on commit 2a879b5

Please sign in to comment.