Skip to content

Commit

Permalink
fix: help messages for enum flag
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge committed Aug 12, 2022
1 parent 5b86847 commit 85077a7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
17 changes: 11 additions & 6 deletions cmd/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ var (
interactive bool
orgId string
dbPassword string
region utils.EnumFlag
plan utils.EnumFlag

region = utils.EnumFlag{
Allowed: make([]string, len(utils.RegionMap)),
}
plan = utils.EnumFlag{
Allowed: []string{string(api.Free), string(api.Pro)},
Value: string(api.Free),
}

projectsCreateCmd = &cobra.Command{
Use: "create <project name>",
Expand Down Expand Up @@ -67,12 +73,11 @@ var (

func init() {
// Setup enum flags
region.Allowed = make([]string, len(utils.RegionMap))
i := 0
for k := range utils.RegionMap {
region.Allowed = append(region.Allowed, k)
region.Allowed[i] = k
i++
}
plan.Allowed = []string{string(api.Free), string(api.Pro)}
plan.Value = string(api.Free)
// Add flags to cobra command
createFlags := projectsCreateCmd.Flags()
createFlags.BoolVarP(&interactive, "interactive", "i", false, "Enables interactive mode.")
Expand Down
2 changes: 0 additions & 2 deletions internal/projects/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ func Run(ctx context.Context, params api.CreateProjectBody, fsys afero.Fs) error
return err
}

// TODO: remove the StatusOK case after 2022-08-20
// if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated {
if resp.JSON201 == nil {
return errors.New("Unexpected error creating project: " + string(resp.Body))
}
Expand Down
2 changes: 1 addition & 1 deletion internal/utils/enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (a *EnumFlag) Set(p string) error {
return false
}
if !isIncluded(a.Allowed, p) {
return fmt.Errorf("%s is not included in [ %s ]", p, strings.Join(a.Allowed, " | "))
return fmt.Errorf("must be one of [ %s ]", strings.Join(a.Allowed, " | "))
}
a.Value = p
return nil
Expand Down

0 comments on commit 85077a7

Please sign in to comment.