diff options
author | Arne Juul <arnej@yahooinc.com> | 2022-08-31 13:43:02 +0000 |
---|---|---|
committer | Arne Juul <arnej@yahooinc.com> | 2022-09-05 11:34:14 +0000 |
commit | 1c2def630b6ee3885d8eb09ff6df39f8205c9c6e (patch) | |
tree | 711de9e0042614b43b8b5b9b04bd99a434ae5c69 /client/go | |
parent | 9747632efc45d76f1c78e8b70b2f6bf8e2d812dd (diff) |
allow indirection via script-utils
Diffstat (limited to 'client/go')
-rw-r--r-- | client/go/cmd/deploy/cmd.go (renamed from client/go/vespa-deploy/cmd.go) | 29 | ||||
-rw-r--r-- | client/go/cmd/logfmt/cmd.go (renamed from client/go/vespa-logfmt/cmd.go) | 7 | ||||
-rw-r--r-- | client/go/script-utils/main.go | 28 | ||||
-rw-r--r-- | client/go/vespa-deploy/main.go | 10 | ||||
-rw-r--r-- | client/go/vespa-logfmt/main.go | 9 |
5 files changed, 40 insertions, 43 deletions
diff --git a/client/go/vespa-deploy/cmd.go b/client/go/cmd/deploy/cmd.go index af97dc098e5..f5cf554834d 100644 --- a/client/go/vespa-deploy/cmd.go +++ b/client/go/cmd/deploy/cmd.go @@ -2,7 +2,7 @@ // vespa-deploy command // Author: arnej -package main +package deploy import ( "fmt" @@ -10,7 +10,6 @@ import ( "github.com/spf13/cobra" "github.com/vespa-engine/vespa/client/go/build" - "github.com/vespa-engine/vespa/client/go/cmd/deploy" ) func reallySimpleHelp(cmd *cobra.Command, args []string) { @@ -19,7 +18,7 @@ func reallySimpleHelp(cmd *cobra.Command, args []string) { func NewDeployCmd() *cobra.Command { var ( - curOptions deploy.Options + curOptions Options ) cobra.EnableCommandSorting = false cmd := &cobra.Command{ @@ -64,15 +63,15 @@ Try 'vespa-deploy help <command>' to get more help`, return cmd } -func newUploadCmd(opts *deploy.Options) *cobra.Command { +func newUploadCmd(opts *Options) *cobra.Command { cmd := &cobra.Command{ Use: "upload <application package>", Run: func(cmd *cobra.Command, args []string) { - opts.Command = deploy.CmdUpload + opts.Command = CmdUpload if opts.Verbose { fmt.Printf("upload %v [%v]\n", opts, args) } - err := deploy.RunUpload(opts, args) + err := RunUpload(opts, args) if err != nil { fmt.Fprintf(os.Stderr, "%s\n", err.Error()) os.Exit(1) @@ -85,15 +84,15 @@ func newUploadCmd(opts *deploy.Options) *cobra.Command { return cmd } -func newPrepareCmd(opts *deploy.Options) *cobra.Command { +func newPrepareCmd(opts *Options) *cobra.Command { cmd := &cobra.Command{ Use: "prepare [<session_id> | <application package>]", Run: func(cmd *cobra.Command, args []string) { - opts.Command = deploy.CmdPrepare + opts.Command = CmdPrepare if opts.Verbose { fmt.Printf("prepare %v [%v]\n", opts, args) } - err := deploy.RunPrepare(opts, args) + err := RunPrepare(opts, args) if err != nil { fmt.Fprintf(os.Stderr, "%s\n", err.Error()) os.Exit(1) @@ -105,15 +104,15 @@ func newPrepareCmd(opts *deploy.Options) *cobra.Command { return cmd } -func newActivateCmd(opts *deploy.Options) *cobra.Command { +func newActivateCmd(opts *Options) *cobra.Command { cmd := &cobra.Command{ Use: "activate [<session_id>]", Run: func(cmd *cobra.Command, args []string) { - opts.Command = deploy.CmdActivate + opts.Command = CmdActivate if opts.Verbose { fmt.Printf("activate %v [%v]\n", opts, args) } - err := deploy.RunActivate(opts, args) + err := RunActivate(opts, args) if err != nil { fmt.Fprintf(os.Stderr, "%s\n", err.Error()) os.Exit(1) @@ -125,15 +124,15 @@ func newActivateCmd(opts *deploy.Options) *cobra.Command { return cmd } -func newFetchCmd(opts *deploy.Options) *cobra.Command { +func newFetchCmd(opts *Options) *cobra.Command { cmd := &cobra.Command{ Use: "fetch <output directory>", Run: func(cmd *cobra.Command, args []string) { - opts.Command = deploy.CmdFetch + opts.Command = CmdFetch if opts.Verbose { fmt.Printf("fetch %v [%v]\n", opts, args) } - err := deploy.RunFetch(opts, args) + err := RunFetch(opts, args) if err != nil { fmt.Fprintf(os.Stderr, "%s\n", err.Error()) os.Exit(1) diff --git a/client/go/vespa-logfmt/cmd.go b/client/go/cmd/logfmt/cmd.go index c36f92304f1..54e82844a30 100644 --- a/client/go/vespa-logfmt/cmd.go +++ b/client/go/cmd/logfmt/cmd.go @@ -2,17 +2,16 @@ // vespa-logfmt command // Author: arnej -package main +package logfmt import ( "github.com/spf13/cobra" "github.com/vespa-engine/vespa/client/go/build" - "github.com/vespa-engine/vespa/client/go/cmd/logfmt" ) func NewLogfmtCmd() *cobra.Command { var ( - curOptions logfmt.Options = logfmt.NewOptions() + curOptions Options = NewOptions() ) cmd := &cobra.Command{ Use: "vespa-logfmt", @@ -21,7 +20,7 @@ func NewLogfmtCmd() *cobra.Command { and converts it to something human-readable`, Version: build.Version, Run: func(cmd *cobra.Command, args []string) { - logfmt.RunLogfmt(&curOptions, args) + RunLogfmt(&curOptions, args) }, } cmd.Flags().VarP(&curOptions.ShowLevels, "level", "l", "turn levels on/off\n") diff --git a/client/go/script-utils/main.go b/client/go/script-utils/main.go index a7160691a5d..7ab16a6f831 100644 --- a/client/go/script-utils/main.go +++ b/client/go/script-utils/main.go @@ -6,16 +6,25 @@ package main import ( "fmt" "os" + "strings" + "github.com/vespa-engine/vespa/client/go/cmd/deploy" + "github.com/vespa-engine/vespa/client/go/cmd/logfmt" "github.com/vespa-engine/vespa/client/go/vespa" ) +func basename(s string) string { + parts := strings.Split(s, "/") + return parts[len(parts)-1] +} + func main() { - if len(os.Args) < 2 { - fmt.Fprintln(os.Stderr, "actions: export-env, ipv6-only") - return + action := basename(os.Args[0]) + if action == "script-utils" && len(os.Args) > 1 { + action = os.Args[1] + os.Args = os.Args[1:] } - switch os.Args[1] { + switch action { case "export-env": vespa.ExportDefaultEnvToSh() case "ipv6-only": @@ -24,7 +33,16 @@ func main() { } else { os.Exit(1) } + case "vespa-deploy": + _ = vespa.FindHome() + cobra := deploy.NewDeployCmd() + cobra.Execute() + case "vespa-logfmt": + _ = vespa.FindHome() + cobra := logfmt.NewLogfmtCmd() + cobra.Execute() default: - fmt.Fprintf(os.Stderr, "unknown action '%s'\n", os.Args[1]) + fmt.Fprintf(os.Stderr, "unknown action '%s'\n", action) + fmt.Fprintln(os.Stderr, "actions: export-env, ipv6-only, vespa-deploy, vespa-logfmt") } } diff --git a/client/go/vespa-deploy/main.go b/client/go/vespa-deploy/main.go deleted file mode 100644 index 549f5511765..00000000000 --- a/client/go/vespa-deploy/main.go +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -// vespa-deploy command -// Author: arnej - -package main - -func main() { - cobra := NewDeployCmd() - cobra.Execute() -} diff --git a/client/go/vespa-logfmt/main.go b/client/go/vespa-logfmt/main.go deleted file mode 100644 index 90a7719a1ef..00000000000 --- a/client/go/vespa-logfmt/main.go +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -// Author: arnej - -package main - -func main() { - cobra := NewLogfmtCmd() - cobra.Execute() -} |