Skip to content

Commit

Permalink
Merge pull request #163 from manifoldco/promptui
Browse files Browse the repository at this point in the history
Create select prompts with details
  • Loading branch information
jeffandersen authored Oct 26, 2017
2 parents 4af04e7 + 2f0eae4 commit 5cac1cc
Show file tree
Hide file tree
Showing 10 changed files with 711 additions and 402 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### Add
- Improved visuals for select boxes

### Fixed
- Project create failure due to Name/Title change
- Set-role should error before prompts
Expand Down
4 changes: 2 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func create(cliCtx *cli.Context) error {
}

plans := filterPlansByProductID(catalog.Plans(), products[productIdx].ID)
planIdx, _, err := prompts.SelectPlan(plans, planName, false)
planIdx, _, err := prompts.SelectPlan(plans, planName)
if err != nil {
return prompts.HandleSelectError(err, "Could not select plan.")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/resize.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func resizeResourceCmd(cliCtx *cli.Context) error {
return errs.ErrNoPlans
}

pIdx, _, err := prompts.SelectPlan(plans, planName, false)
pIdx, _, err := prompts.SelectPlan(plans, planName)
if err != nil {
return prompts.HandleSelectError(err, "Could not select Plan")
}
Expand Down
25 changes: 25 additions & 0 deletions data/catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package catalog
import (
"context"
"errors"
"sort"
"strings"

"github.com/manifoldco/go-manifold"
hierr "github.com/reconquest/hierr-go"
Expand Down Expand Up @@ -54,6 +56,17 @@ func (c *Catalog) Plans() []*catalogModels.Plan {
plans = append(plans, p)
}

sort.Slice(plans, func(i, j int) bool {
a := plans[i]
b := plans[j]

if *a.Body.Cost == *b.Body.Cost {
return strings.ToLower(string(a.Body.Label)) <
strings.ToLower(string(b.Body.Label))
}
return *a.Body.Cost < *b.Body.Cost
})

return plans
}

Expand All @@ -64,6 +77,12 @@ func (c *Catalog) Products() []*catalogModels.Product {
products = append(products, p)
}

sort.Slice(products, func(i, j int) bool {
a := string(products[i].Body.Label)
b := string(products[j].Body.Label)
return strings.ToLower(a) < strings.ToLower(b)
})

return products
}

Expand All @@ -74,6 +93,12 @@ func (c *Catalog) Regions() []*catalogModels.Region {
regions = append(regions, r)
}

sort.Slice(regions, func(i, j int) bool {
a := regions[i]
b := regions[j]
return strings.ToLower(string(a.Body.Name)) < strings.ToLower(string(b.Body.Name))
})

return regions
}

Expand Down
Loading

0 comments on commit 5cac1cc

Please sign in to comment.