Skip to content

Commit

Permalink
chore(go.d): simplify cli is help (netdata#19246)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyam8 authored Dec 18, 2024
1 parent 93bf42c commit c3b8eef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 1 addition & 4 deletions src/go/cmd/godplugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package main

import (
"errors"
"fmt"
"log/slog"
"os"
Expand All @@ -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"

Expand Down Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion src/go/plugin/go.d/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"strconv"

"github.com/jessevdk/go-flags"

"github.com/netdata/netdata/go/plugins/pkg/executable"
)

// Option defines command line options.
Expand All @@ -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)
Expand All @@ -40,3 +42,7 @@ func Parse(args []string) (*Option, error) {

return opt, nil
}

func IsHelp(err error) bool {
return flags.WroteHelp(err)
}

0 comments on commit c3b8eef

Please sign in to comment.