Skip to content

Commit

Permalink
Move help flag determination to function and make it easy to add more…
Browse files Browse the repository at this point in the history
… cmds if we want
  • Loading branch information
rpearce committed Sep 18, 2022
1 parent e504e56 commit 29658d4
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ func usage() {
fmt.Printf("usage: %s [100..505] [-v|--verbose]\n", os.Args[0])
}

func isAskingForHelp() bool {
var help bool

flag.BoolVar(&help, "help", false, helpUsage)
flag.BoolVar(&help, "h", false, helpUsage)
flag.Parse()

return help
}

type Runner interface {
Init([]string) error
Run() error
Expand Down Expand Up @@ -352,18 +362,12 @@ func root(args []string) error {

flag.Usage = usage

var needsHelp bool

flag.BoolVar(&needsHelp, "help", false, helpUsage)
flag.BoolVar(&needsHelp, "h", false, helpUsage)
flag.Parse()

if needsHelp {
if isAskingForHelp() {
usage()
return nil
}

var cmds []Runner
cmds := []Runner{}

for code := range statuses {
cmds = append(cmds, NewStatusCodeCommand(code))
Expand Down

0 comments on commit 29658d4

Please sign in to comment.