Skip to content

Commit 3dd0e57

Browse files
author
Matthew Fisher
committed
Merge pull request #328 from bacongobbler/port-deis-version
feat(client): document deis version
2 parents e06d198 + a252b86 commit 3dd0e57

2 files changed

Lines changed: 38 additions & 5 deletions

File tree

client/deis.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"syscall"
99

1010
"github.com/deis/workflow/client/parser"
11-
"github.com/deis/workflow/client/version"
1211
docopt "github.com/docopt/docopt-go"
1312
)
1413

@@ -25,6 +24,11 @@ The Deis command-line client issues API calls to a Deis controller.
2524
2625
Usage: deis <command> [<args>...]
2726
27+
Option flags::
28+
29+
-h --help display help information
30+
-v --version display client version
31+
2832
Auth commands::
2933
3034
register register a new user with a controller
@@ -47,6 +51,7 @@ Subcommands, use 'deis help [subcommand]' to learn more::
4751
perms manage permissions for applications
4852
git manage git for applications
4953
users manage users
54+
version display client version
5055
5156
Shortcut commands, use 'deis shortcuts' to see all::
5257
@@ -64,7 +69,7 @@ Use 'git push deis master' to deploy to an application.
6469
// Reorganize some command line flags and commands.
6570
command, argv := parseArgs(argv)
6671
// Give docopt an optional final false arg so it doesn't call os.Exit().
67-
_, err := docopt.Parse(usage, []string{command}, false, version.Version, true, false)
72+
_, err := docopt.Parse(usage, []string{command}, false, "", true, false)
6873

6974
if err != nil {
7075
fmt.Fprintln(os.Stderr, err)
@@ -107,11 +112,11 @@ Use 'git push deis master' to deploy to an application.
107112
err = parser.Git(argv)
108113
case "users":
109114
err = parser.Users(argv)
115+
case "version":
116+
err = parser.Version(argv)
110117
case "help":
111118
fmt.Print(usage)
112119
return 0
113-
case "--version":
114-
return 0
115120
default:
116121
env := os.Environ()
117122
extCmd := "deis-" + command
@@ -149,9 +154,12 @@ Use 'git push deis master' to deploy to an application.
149154
// expands shortcuts and formats commands to be properly routed.
150155
func parseArgs(argv []string) (string, []string) {
151156
if len(argv) == 1 {
152-
// rearrange "deis --help" as "deis help"
153157
if argv[0] == "--help" || argv[0] == "-h" {
158+
// rearrange "deis --help" as "deis help"
154159
argv[0] = "help"
160+
} else if argv[0] == "--version" || argv[0] == "-v" {
161+
// rearrange "deis --version" as "deis version"
162+
argv[0] = "version"
155163
}
156164
}
157165

client/parser/version.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package parser
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/deis/workflow/client/version"
7+
docopt "github.com/docopt/docopt-go"
8+
)
9+
10+
// Version displays the client version
11+
func Version(argv []string) error {
12+
usage := `
13+
Displays the client version.
14+
15+
Usage: deis version
16+
17+
Use 'deis help [command]' to learn more.
18+
`
19+
if _, err := docopt.Parse(usage, argv, true, "", false, true); err != nil {
20+
return err
21+
}
22+
23+
fmt.Println(version.Version)
24+
return nil
25+
}

0 commit comments

Comments
 (0)