Skip to content

Commit c71a91c

Browse files
reworked main help menu
1 parent 0a08f7f commit c71a91c

8 files changed

Lines changed: 76 additions & 138 deletions

File tree

_patches/patch-task.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,30 @@ cd "$(dirname $0)"
2121
HERE=$PWD
2222
SHVER=$(git ls-remote https://github.com/sciabarracom/sh | awk '/refs\/heads\/openserverless/{print $1}')
2323
STAG="v3.38.0"
24-
DTAG="v3.38.10"
24+
DTAG="v3.38.11"
2525
cd task
2626
git reset --hard
2727
go clean -cache -modcache
2828
git checkout "$STAG" -B openserverless
2929
mkdir -p cmd/taskmain
30+
31+
sed -i -e 's/func init/func FlagInit/' internal/flags/flags.go
32+
sed -i -e 's/func init/func FlagInit/' internal/experiments/experiments.go
33+
3034
cat cmd/task/task.go \
3135
| sed -e 's/package main/package taskmain/' \
3236
| sed -e 's/func main()/func _main()/' \
3337
| tee cmd/taskmain/task.go
34-
sed -i -e 's/func init/func FlagInit/' internal/flags/flags.go
35-
cat <<EOF >>cmd/taskmain/task.go
38+
39+
cat <<EOF >>cmd/taskmain/task.go
3640
3741
var todoFlagInit = true
3842
3943
func Task(_args []string) (int, error) {
4044
os.Args = _args
4145
if todoFlagInit {
4246
flags.FlagInit()
47+
experiments.FlagInit()
4348
todoFlagInit = false
4449
}
4550
if err := run(); err != nil {
@@ -77,7 +82,8 @@ sed -i -e '/mvdan.cc/g' go.mod
7782
go get github.com/sciabarracom/sh/v3@$SHVER
7883
go mod tidy
7984
git commit -m "patching sh for ops" -a
80-
go build
85+
go build
86+
8187
git tag $DTAG
8288
git push origin-auth openserverless -f --tags
8389
VER=$(git rev-parse HEAD)

auth/login.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type LoginResult struct {
4343
const usage = `Usage:
4444
ops login <apihost> [<user>]
4545
46-
Login to an OpenServerless instance. If no user is specified, the default user "opsolaris" is used.
46+
Login to an OpenServerless instance. If no user is specified, the default user "nuvolaris" is used.
4747
You can set the environment variables OPS_APIHOST and OPS_USER to avoid specifying them on the command line.
4848
You can set OPS_PASSWORD to avoid entering the password interactively.
4949

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ require (
2121
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
2222
github.com/sciabarracom/openwhisk-cli v1.2.1
2323
github.com/sciabarracom/sh/v3 v3.8.3
24-
github.com/sciabarracom/task/v3 v3.38.10
24+
github.com/sciabarracom/task/v3 v3.38.11
2525
github.com/stretchr/testify v1.9.0
2626
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8
2727
github.com/zalando/go-keyring v0.2.5

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,8 @@ github.com/sciabarracom/sh/v3 v3.8.3 h1:5afHdZzNkW5vgUMP7gHUpBYHezn3BoQsyNgKXKdT
347347
github.com/sciabarracom/sh/v3 v3.8.3/go.mod h1:CeMVr3PRLhlUrS+VPLTp8dS5/6xNzmmX0h/WVHRR6DA=
348348
github.com/sciabarracom/task/v3 v3.38.10 h1:KSu6B2CuHWail7rlTx5W72qM1klJbED3z2k7RzBvMkE=
349349
github.com/sciabarracom/task/v3 v3.38.10/go.mod h1:EMjHs6YrTofApnomes/CNiGQ1odZUZF6PTqmYW9EBic=
350+
github.com/sciabarracom/task/v3 v3.38.11 h1:TZeaepSVc9Lx7TowAqIV3K9IZQh+jYgKNDpBNIg38uU=
351+
github.com/sciabarracom/task/v3 v3.38.11/go.mod h1:EMjHs6YrTofApnomes/CNiGQ1odZUZF6PTqmYW9EBic=
350352
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
351353
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
352354
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=

main.go

Lines changed: 59 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -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

264263
func 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
}

tests/mvrmem.bats

Lines changed: 0 additions & 68 deletions
This file was deleted.

tools/tools.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,11 @@ func RunTool(name string, args []string) (int, error) {
170170
return Rename()
171171

172172
case "remove":
173-
os.Args = append([]string{"rename"}, args...)
173+
os.Args = append([]string{"remove"}, args...)
174174
return Remove()
175175

176176
case "extract":
177-
os.Args = append([]string{"untar"}, args...)
177+
os.Args = append([]string{"extract"}, args...)
178178
return Extract()
179179

180180
case "empty":
@@ -188,9 +188,6 @@ func RunTool(name string, args []string) (int, error) {
188188
}
189189

190190
func Help(mainTools []string) {
191-
fmt.Println("Infos:")
192-
fmt.Println("-v | --version")
193-
fmt.Println("-h | --help")
194191
fmt.Println("Tools (use -<tool> -h for help):")
195192
availableTools := append(mainTools, ToolList...)
196193
slices.Sort(availableTools)

0 commit comments

Comments
 (0)