From c3b8eef463cee301ce5480aa7283e291c9df072e Mon Sep 17 00:00:00 2001 From: Ilya Mashchenko Date: Wed, 18 Dec 2024 14:24:59 +0200 Subject: [PATCH] chore(go.d): simplify cli is help (#19246) --- src/go/cmd/godplugin/main.go | 5 +---- src/go/plugin/go.d/cli/cli.go | 8 +++++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/go/cmd/godplugin/main.go b/src/go/cmd/godplugin/main.go index d31c837f22e268..00fd9199a51b76 100644 --- a/src/go/cmd/godplugin/main.go +++ b/src/go/cmd/godplugin/main.go @@ -3,7 +3,6 @@ package main import ( - "errors" "fmt" "log/slog" "os" @@ -15,7 +14,6 @@ import ( "github.com/netdata/netdata/go/plugins/plugin/go.d/agent" "github.com/netdata/netdata/go/plugins/plugin/go.d/cli" - "github.com/jessevdk/go-flags" "go.uber.org/automaxprocs/maxprocs" "golang.org/x/net/http/httpproxy" @@ -75,8 +73,7 @@ func main() { func parseCLI() *cli.Option { opt, err := cli.Parse(os.Args) if err != nil { - var flagsErr *flags.Error - if errors.As(err, &flagsErr) && errors.Is(flagsErr.Type, flags.ErrHelp) { + if cli.IsHelp(err) { os.Exit(0) } os.Exit(1) diff --git a/src/go/plugin/go.d/cli/cli.go b/src/go/plugin/go.d/cli/cli.go index 646bdf121e7db5..54ff12a2265875 100644 --- a/src/go/plugin/go.d/cli/cli.go +++ b/src/go/plugin/go.d/cli/cli.go @@ -6,6 +6,8 @@ import ( "strconv" "github.com/jessevdk/go-flags" + + "github.com/netdata/netdata/go/plugins/pkg/executable" ) // Option defines command line options. @@ -24,7 +26,7 @@ func Parse(args []string) (*Option, error) { UpdateEvery: 1, } parser := flags.NewParser(opt, flags.Default) - parser.Name = "orchestrator" + parser.Name = executable.Name parser.Usage = "[OPTIONS] [update every]" rest, err := parser.ParseArgs(args) @@ -40,3 +42,7 @@ func Parse(args []string) (*Option, error) { return opt, nil } + +func IsHelp(err error) bool { + return flags.WroteHelp(err) +}