github.com/netdata/go.d.plugin@v0.58.1/cli/cli.go (about) 1 // SPDX-License-Identifier: GPL-3.0-or-later 2 3 package cli 4 5 import ( 6 "strconv" 7 8 "github.com/jessevdk/go-flags" 9 ) 10 11 // Option defines command line options. 12 type Option struct { 13 UpdateEvery int 14 Module string `short:"m" long:"modules" description:"module name to run" default:"all"` 15 ConfDir []string `short:"c" long:"config-dir" description:"config dir to read"` 16 WatchPath []string `short:"w" long:"watch-path" description:"config path to watch"` 17 Debug bool `short:"d" long:"debug" description:"debug mode"` 18 Version bool `short:"v" long:"version" description:"display the version and exit"` 19 } 20 21 // Parse returns parsed command-line flags in Option struct 22 func Parse(args []string) (*Option, error) { 23 opt := &Option{ 24 UpdateEvery: 1, 25 } 26 parser := flags.NewParser(opt, flags.Default) 27 parser.Name = "orchestrator" 28 parser.Usage = "[OPTIONS] [update every]" 29 30 rest, err := parser.ParseArgs(args) 31 if err != nil { 32 return nil, err 33 } 34 35 if len(rest) > 1 { 36 if opt.UpdateEvery, err = strconv.Atoi(rest[1]); err != nil { 37 return nil, err 38 } 39 } 40 41 return opt, nil 42 }