Skip to content

Commit 0ae9d90

Browse files
author
Matthew Fisher
committed
feat(deis): add deis shortcuts command
This used to be a CLI command, but was lost in the great Go client refactor way back in Deis v1.
1 parent e233d34 commit 0ae9d90

4 files changed

Lines changed: 107 additions & 22 deletions

File tree

cli/cli.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package cli
2+
3+
var Shortcuts = map[string]string{
4+
"create": "apps:create",
5+
"destroy": "apps:destroy",
6+
"info": "apps:info",
7+
"login": "auth:login",
8+
"logout": "auth:logout",
9+
"logs": "apps:logs",
10+
"open": "apps:open",
11+
"passwd": "auth:passwd",
12+
"pull": "builds:create",
13+
"register": "auth:register",
14+
"rollback": "releases:rollback",
15+
"run": "apps:run",
16+
"scale": "ps:scale",
17+
"sharing": "perms:list",
18+
"sharing:list": "perms:list",
19+
"sharing:add": "perms:create",
20+
"sharing:remove": "perms:delete",
21+
"whoami": "auth:whoami",
22+
}

cmd/shortcuts.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"sort"
6+
7+
"github.com/deis/workflow-cli/cli"
8+
)
9+
10+
// Shortcuts displays all relevant shortcuts for the CLI.
11+
func ShortcutsList() error {
12+
var (
13+
strBuilder string = ""
14+
keys []string
15+
)
16+
17+
// NOTE(bacongobbler): go does not guarantee an iteration order when iterating over a map,
18+
// so to work around this we can sort the keys and iterate using the key array
19+
for k := range cli.Shortcuts {
20+
keys = append(keys, k)
21+
}
22+
sort.Strings(keys)
23+
24+
for _, k := range keys {
25+
strBuilder += fmt.Sprintf("%s -> %s\n", k, cli.Shortcuts[k])
26+
}
27+
28+
fmt.Println(strBuilder)
29+
30+
return nil
31+
}

deis.go

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strings"
88
"syscall"
99

10+
"github.com/deis/workflow-cli/cli"
1011
"github.com/deis/workflow-cli/parser"
1112
docopt "github.com/docopt/docopt-go"
1213
)
@@ -116,6 +117,8 @@ Use 'git push deis master' to deploy to an application.
116117
err = parser.Registry(argv)
117118
case "releases":
118119
err = parser.Releases(argv)
120+
case "shortcuts":
121+
err = parser.Shortcuts(argv)
119122
case "tags":
120123
err = parser.Tags(argv)
121124
case "users":
@@ -192,28 +195,7 @@ func parseArgs(argv []string) (string, []string) {
192195
}
193196

194197
func replaceShortcut(command string) string {
195-
shortcuts := map[string]string{
196-
"create": "apps:create",
197-
"destroy": "apps:destroy",
198-
"info": "apps:info",
199-
"login": "auth:login",
200-
"logout": "auth:logout",
201-
"logs": "apps:logs",
202-
"open": "apps:open",
203-
"passwd": "auth:passwd",
204-
"pull": "builds:create",
205-
"register": "auth:register",
206-
"rollback": "releases:rollback",
207-
"run": "apps:run",
208-
"scale": "ps:scale",
209-
"sharing": "perms:list",
210-
"sharing:list": "perms:list",
211-
"sharing:add": "perms:create",
212-
"sharing:remove": "perms:delete",
213-
"whoami": "auth:whoami",
214-
}
215-
216-
expandedCommand := shortcuts[command]
198+
expandedCommand := cli.Shortcuts[command]
217199
if expandedCommand == "" {
218200
return command
219201
}

parser/shortcuts.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package parser
2+
3+
import (
4+
"github.com/deis/workflow-cli/cmd"
5+
docopt "github.com/docopt/docopt-go"
6+
)
7+
8+
// Shortcuts displays all relevant shortcuts for the CLI.
9+
func Shortcuts(argv []string) error {
10+
usage := `
11+
Valid commands for shortcuts:
12+
13+
shortcuts:list list all relevant shortcuts for the CLI
14+
15+
Use 'deis help [command]' to learn more.
16+
`
17+
18+
switch argv[0] {
19+
case "shortcuts:list":
20+
return shortcutsList(argv)
21+
default:
22+
if printHelp(argv, usage) {
23+
return nil
24+
}
25+
26+
if argv[0] == "shortcuts" {
27+
argv[0] = "shortcuts:list"
28+
return shortcutsList(argv)
29+
}
30+
31+
PrintUsage()
32+
return nil
33+
}
34+
}
35+
36+
func shortcutsList(argv []string) error {
37+
usage := `
38+
Lists all relevant shortcuts for the CLI
39+
40+
Usage: deis shortcuts:list
41+
`
42+
43+
_, err := docopt.Parse(usage, argv, true, "", false, true)
44+
45+
if err != nil {
46+
return err
47+
}
48+
49+
return cmd.ShortcutsList()
50+
}

0 commit comments

Comments
 (0)