@@ -23,13 +23,13 @@ import (
2323 "os"
2424 "os/exec"
2525 "path/filepath"
26- "slices"
2726 "strings"
2827 "time"
2928
3029 "github.com/apache/openserverless-cli/auth"
3130 "github.com/apache/openserverless-cli/config"
3231 "github.com/apache/openserverless-cli/tools"
32+ "golang.org/x/exp/slices"
3333
3434 "github.com/mitchellh/go-homedir"
3535
@@ -116,23 +116,22 @@ func InfoAndExit(args []string) {
116116 if len (args ) < 2 {
117117 fmt .Println ("Welcome to ops, the all-mighty, extensibile apache OPenServerless CLI Tool." )
118118 fmt .Println ("Let's start with the basics:" )
119- fmt .Println ("-v | --version version (mention this when you ask for help )" )
120- fmt .Println ("-h | --help help (the manuale is here )" )
121- fmt .Println ("-u | --update update (get the latest version of everything )" )
122- fmt .Println ("-i | -- info CLI infos (let's check the CLI)" )
123- fmt .Println ("-c | --config manage config (let's check the server configuration )" )
124- fmt .Println ("-l | -- login login (you have to login first, you know )" )
125- fmt .Println ("--i-really-want-to-reset (if you are desperate and nothing works )" )
126- fmt .Println ("But wait! There is more, much much more. Please RTFM. " )
119+ fmt .Println ("-h | -help list commands (top level command, start here )" )
120+ fmt .Println ("-t | -tools list tools (embedded tools, prefixed by '-' )" )
121+ fmt .Println ("-v | -version current version (mention this when you ask for help )" )
122+ fmt .Println ("-i | -info CLI infos (let's check the CLI)" )
123+ fmt .Println ("-u | -update download latest (get the latest commands and prerequisites )" )
124+ fmt .Println ("-l | -login access system (you have to login first)" )
125+ fmt .Println ("-c | -config manage config (server configuration )" )
126+ fmt .Println ("-reset clean downloads (if nothing works, try this) " )
127127 os .Exit (0 )
128128 }
129129 // if we have at least one arg
130130 switch args [1 ] {
131- case "-v" , "-- version" :
131+ case "-v" , "-version" :
132132 fmt .Println (OpsVersion )
133133 os .Exit (0 )
134-
135- case "-h" , "--help" :
134+ case "-t" , "-tools" :
136135 tools .Help (mainTools )
137136 os .Exit (0 )
138137 default :
@@ -145,7 +144,7 @@ func executeTools(cmd string, args []string, opsHome string) int {
145144
146145 switch cmd {
147146 case "" , "task" :
148- exitCode , err := Task (args [ 2 :] ... )
147+ exitCode , err := Task (args ... )
149148 if err != nil {
150149 log .Println (err )
151150 }
@@ -198,7 +197,7 @@ func executeTools(cmd string, args []string, opsHome string) int {
198197 }
199198 return 0
200199
201- case "i-really-want-to-reset" , " reset" :
200+ case "reset" :
202201 home := os .Getenv ("OPS_HOME" )
203202 if home == "" {
204203 log .Fatal ("cannot determine the ops home dir" )
@@ -222,7 +221,7 @@ func executeTools(cmd string, args []string, opsHome string) int {
222221 if err != nil {
223222 log .Fatal ("ops reset error:" , err .Error ())
224223 }
225- fmt .Println ("ops reset complete" )
224+ fmt .Println ("ops - reset complete - execute ops -update to reload " )
226225 return 0
227226
228227 case "retry" :
@@ -258,7 +257,7 @@ func executeTools(cmd string, args []string, opsHome string) int {
258257 warn ("unknown tool" , "-" + cmd )
259258 return 1
260259 }
261- return 0 // unreachable - or it should be!
260+ // return 0 // unreachable - or it should be!
262261}
263262
264263func Main () {
@@ -277,6 +276,27 @@ func Main() {
277276 trace ("WSK_RUNTIMES_JSON len=" , len (WSK_RUNTIMES_JSON ))
278277 }
279278
279+ // in case args[1] is a wsk wrapper command invoke it and exit
280+ // CLI: ops action ... (wsk wrapper)
281+ if len (os .Args ) > 1 {
282+ if expand , ok := IsWskWrapperCommand (os .Args [1 ]); ok {
283+ trace ("wsk wrapper command" )
284+ debug ("extracted cmd" , expand )
285+ rest := os .Args [2 :]
286+ debug ("extracted args" , rest )
287+
288+ // if "invoke" is in the command, parse all a=b into -p a b
289+ if (len (expand ) > 2 && expand [2 ] == "invoke" ) || slices .Contains (rest , "invoke" ) {
290+ rest = parseInvokeArgs (rest )
291+ }
292+
293+ if err := tools .Wsk (expand , rest ... ); err != nil {
294+ log .Fatalf ("error: %s" , err .Error ())
295+ }
296+ os .Exit (0 )
297+ }
298+ }
299+
280300 // set runtime version as environment variable
281301 if os .Getenv ("OPS_VERSION" ) != "" {
282302 OpsVersion = os .Getenv ("OPS_VERSION" )
@@ -368,42 +388,23 @@ func Main() {
368388 log .Fatalf ("failed preflight check: %s" , err .Error ())
369389 }
370390
371- // in case args[1] is a wsk wrapper command invoke it and exit
372- // CLI: ops action ... (wsk wrapper)
373- if len (os .Args ) > 1 {
374- if expand , ok := IsWskWrapperCommand (os .Args [1 ]); ok {
375- trace ("wsk wrapper command" )
376- debug ("extracted cmd" , expand )
377- rest := os .Args [2 :]
378- debug ("extracted args" , rest )
379-
380- // if "invoke" is in the command, parse all a=b into -p a b
381- if (len (expand ) > 2 && expand [2 ] == "invoke" ) || slices .Contains (rest , "invoke" ) {
382- rest = parseInvokeArgs (rest )
383- }
384-
385- if err := tools .Wsk (expand , rest ... ); err != nil {
386- log .Fatalf ("error: %s" , err .Error ())
387- }
388- os .Exit (0 )
389- }
390- }
391-
392391 // first argument with prefix "-" is considered an embedded tool
393392 // using "-" or "--" or "-task" invokes the embedded task
394393 // CLI: ops -<tool> (embedded tool)
395- if len (os .Args ) > 1 && len (os .Args [1 ]) > 0 && os .Args [1 ][0 ] == '-' {
396- cmd := os .Args [1 ]
397- // remove extra hyphen if any
398- if len (cmd ) > 0 && cmd [0 ] == '-' {
399- cmd = cmd [1 :]
394+ args := os .Args
395+ if len (args ) > 1 && len (args [1 ]) > 0 && args [1 ][0 ] == '-' {
396+ cmd := args [1 ][1 :]
397+ if cmd != "h" && cmd != "help" {
398+ // execute the embeded tool and exit
399+ exitCode := executeTools (cmd , args [2 :], opsHome )
400+ os .Exit (exitCode )
401+ } else {
402+ // remove -t to show tasks
403+ args = args [1 :]
400404 }
401- // execute the embeded tool and exit
402- exitCode := executeTools (cmd , os .Args [1 :], opsHome )
403- os .Exit (exitCode )
404405 }
405406
406- if err := runOps (opsRootDir , os . Args [ 1 :] ); err != nil {
407+ if err := runOps (opsRootDir , args ); err != nil {
407408 log .Fatalf ("task execution error: %s" , err .Error ())
408409 }
409410}
@@ -522,19 +523,19 @@ func buildConfigMap(opsRootPath string, configPath string) (*config.ConfigMap, e
522523 return & configMap , nil
523524}
524525
525- func IsWskWrapperCommand (name string ) ([]string , bool ) {
526- wskWrapperCommands := map [string ][]string {
527- "action" : {"wsk" , "action" },
528- "activation" : {"wsk" , "activation" },
529- "invoke" : {"wsk" , "action" , "invoke" , "-r" },
530- "logs" : {"wsk" , "activation" , "logs" },
531- "package" : {"wsk" , "package" },
532- "result" : {"wsk" , "activation" , "result" },
533- "rule" : {"wsk" , "rule" },
534- "trigger" : {"wsk" , "trigger" },
535- "url" : {"wsk" , "action" , "get" , "--url" },
536- }
526+ var wskWrapperCommands = map [string ][]string {
527+ "action" : {"wsk" , "action" },
528+ "activation" : {"wsk" , "activation" },
529+ "invoke" : {"wsk" , "action" , "invoke" , "-r" },
530+ "logs" : {"wsk" , "activation" , "logs" },
531+ "package" : {"wsk" , "package" },
532+ "result" : {"wsk" , "activation" , "result" },
533+ "rule" : {"wsk" , "rule" },
534+ "trigger" : {"wsk" , "trigger" },
535+ "url" : {"wsk" , "action" , "get" , "--url" },
536+ }
537537
538+ func IsWskWrapperCommand (name string ) ([]string , bool ) {
538539 cmd , ok := wskWrapperCommands [name ]
539540 return cmd , ok
540541}
0 commit comments