Skip to content

Commit fb5e41c

Browse files
author
Vaughn Dice
authored
Merge pull request #275 from vdice/sort-labels
feat(cmd/labels.go): sort labels when listing
2 parents c9fb830 + 8955e7e commit fb5e41c

5 files changed

Lines changed: 33 additions & 16 deletions

File tree

cmd/apps_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ lorem-ipsum-cmd-1911796442-48b58 up (v2)
211211
lorem-ipsum
212212
213213
=== lorem-ipsum Label
214-
team: frontend
214+
team: frontend
215215
216216
`, "output")
217217
}

cmd/labels.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ package cmd
22

33
import (
44
"fmt"
5+
"strings"
6+
7+
"github.com/deis/pkg/prettyprint"
8+
59
"github.com/deis/controller-sdk-go/api"
610
"github.com/deis/controller-sdk-go/appsettings"
7-
"strings"
811
)
912

1013
// LabelsList list app's labels
@@ -20,12 +23,21 @@ func (d *DeisCmd) LabelsList(appID string) error {
2023
return err
2124
}
2225

26+
sortedLabels := sortKeys(appSettings.Label)
27+
2328
d.Printf("=== %s Label\n", appID)
2429

25-
if appSettings.Label == nil || len(appSettings.Label) == 0 {
30+
if len(sortedLabels) == 0 {
2631
d.Println("No labels found.")
2732
} else {
28-
d.Println(appSettings.Label)
33+
labels := make(map[string]string)
34+
35+
// appSettings.Label is type interface, so it needs to be converted to a string
36+
for _, label := range sortedLabels {
37+
labels[label+":"] = fmt.Sprintf("%v", appSettings.Label[label])
38+
}
39+
40+
d.Print(prettyprint.PrettyTabs(labels, 6))
2941
}
3042

3143
return nil

cmd/labels_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestLabelsList(t *testing.T) {
2727
fmt.Fprintf(w, `{
2828
"owner": "jim",
2929
"app": "rivendell",
30-
"label": {"git_repo": "https://github.com/deis/controller-sdk-go", "team" : "deis"},
30+
"label": {"team" : "deis", "git_repo": "https://github.com/deis/controller-sdk-go"},
3131
"created": "2014-01-01T00:00:00UTC",
3232
"updated": "2014-01-01T00:00:00UTC",
3333
"uuid": "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75"
@@ -37,8 +37,8 @@ func TestLabelsList(t *testing.T) {
3737
err = cmdr.LabelsList("rivendell")
3838
assert.NoErr(t, err)
3939
assert.Equal(t, strings.TrimSpace(b.String()), `=== rivendell Label
40-
git_repo: https://github.com/deis/controller-sdk-go
41-
team: deis`, "output")
40+
git_repo: https://github.com/deis/controller-sdk-go
41+
team: deis`, "output")
4242

4343
server.Mux.HandleFunc("/v2/apps/mordor/settings/", func(w http.ResponseWriter, r *http.Request) {
4444
testutil.SetHeaders(w)

glide.lock

Lines changed: 13 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

glide.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ import:
1616
- package: github.com/olekukonko/tablewriter
1717
- package: github.com/arschles/assert
1818
- package: github.com/deis/controller-sdk-go
19-
version: 685c7f75bc1c4b57899a7cde55d945aa16129513
19+
version: e4abe62d2accc3168b82ff54cb7e8aff2764d03b

0 commit comments

Comments
 (0)