@@ -62,20 +62,19 @@ Shortcut commands, use 'deis shortcuts' to see all::
6262Use 'git push deis master' to deploy to an application.
6363`
6464 // Reorganize some command line flags and commands.
65- argv = parseArgs (argv )
65+ command , argv : = parseArgs (argv )
6666 // Give docopt an optional final false arg so it doesn't call os.Exit().
67- args , err := docopt .Parse (usage , argv , false , version .Version , true , false )
67+ _ , err := docopt .Parse (usage , [] string { command } , false , version .Version , true , false )
6868
6969 if err != nil {
7070 fmt .Println (err )
7171 return 1
7272 }
7373
74- if len (args ) == 0 {
74+ if len (argv ) == 0 {
7575 return 0
7676 }
7777
78- command := args ["<command>" ]
7978 // Dispatch the command, passing the argv through so subcommands can
8079 // re-parse it according to their usage strings.
8180 switch command {
@@ -110,18 +109,27 @@ Use 'git push deis master' to deploy to an application.
110109 case "help" :
111110 fmt .Print (usage )
112111 return 0
112+ case "--version" :
113+ return 0
113114 default :
114115 env := os .Environ ()
115- command = "deis-" + argv [ 0 ]
116+ extCmd : = "deis-" + command
116117
117- binary , err := exec .LookPath (command .( string ) )
118+ binary , err := exec .LookPath (extCmd )
118119 if err != nil {
119120 parser .PrintUsage ()
120121 return 1
121122 }
122123
123- cmdArgv := []string {command .(string )}
124- cmdArgv = append (cmdArgv , argv [1 :]... )
124+ cmdArgv := []string {extCmd }
125+
126+ cmdSplit := strings .Split (argv [0 ], command + ":" )
127+
128+ if len (cmdSplit ) > 1 {
129+ argv [0 ] = cmdSplit [1 ]
130+ }
131+
132+ cmdArgv = append (cmdArgv , argv ... )
125133
126134 err = syscall .Exec (binary , cmdArgv , env )
127135 if err != nil {
@@ -138,35 +146,35 @@ Use 'git push deis master' to deploy to an application.
138146
139147// parseArgs returns the provided args with "--help" as the last arg if need be,
140148// expands shortcuts and formats commands to be properly routed.
141- func parseArgs (argv []string ) []string {
149+ func parseArgs (argv []string ) ( string , []string ) {
142150 if len (argv ) == 1 {
143- // rearrange "deisctl --help" as "deisctl help"
151+ // rearrange "deis --help" as "deis help"
144152 if argv [0 ] == "--help" || argv [0 ] == "-h" {
145153 argv [0 ] = "help"
146154 }
147155 }
148156
149157 if len (argv ) >= 2 {
150- // Rearrange "deisctl help <command>" to "deisctl <command> --help".
158+ // Rearrange "deis help <command>" to "deis <command> --help".
151159 if argv [0 ] == "help" || argv [0 ] == "--help" || argv [0 ] == "-h" {
152160 argv = append (argv [1 :], "--help" )
153161 }
154162 }
155163
156- // Split commands with colons [apps:create, ...] -> [apps, create, ...].
157164 if len (argv ) > 0 {
158165 argv [0 ] = replaceShortcut (argv [0 ])
159166
160167 index := strings .Index (argv [0 ], ":" )
161168
162169 if index != - 1 {
163170 command := argv [0 ]
164- argv [0 ] = command [:index ]
165- argv = append (argv [:1 ], append ([]string {command [(index + 1 ):]}, argv [1 :]... )... )
171+ return command [:index ], argv
166172 }
173+
174+ return argv [0 ], argv
167175 }
168176
169- return argv
177+ return "" , argv
170178}
171179
172180func replaceShortcut (command string ) string {
0 commit comments