Skip to content

Commit

Permalink
Stop printing usage when a flag is unknown.
Browse files Browse the repository at this point in the history
The usage text is long and makes it hard to notice the actual error.
  • Loading branch information
bojanz committed Aug 11, 2023
1 parent a9607d9 commit 3598592
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 4 additions & 2 deletions cmd/broom/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const addDescription = `Add a new profile`

func addCmd(args []string) {
authTypes := broom.AuthTypes()
flags := flag.NewFlagSet("add", flag.ExitOnError)
flags := flag.NewFlagSet("add", flag.ContinueOnError)
var (
help = flags.BoolP("help", "h", false, "Display this help text and exit")
authCredentials = flags.String("auth", "", "Auth credentials (e.g. access token or API key). Used to authenticate every request")
Expand All @@ -29,7 +29,9 @@ func addCmd(args []string) {
serverURL = flags.String("server-url", "", "Server URL")
)
flags.SortFlags = false
flags.Parse(args)
if err := flags.Parse(args); err != nil {
exitWithError(err)
}
if *help || flags.NArg() < 3 {
addUsage()
flagUsage(flags)
Expand Down
6 changes: 4 additions & 2 deletions cmd/broom/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
const profileDescription = `List the profile's operations`

func profileCmd(args []string) {
flags := flag.NewFlagSet("profile", flag.ExitOnError)
flags := flag.NewFlagSet("profile", flag.ContinueOnError)
var (
help = flags.BoolP("help", "h", false, "Display this help text and exit")
headers = flags.StringArrayP("header", "H", nil, "Header. Can be used multiple times")
Expand All @@ -29,7 +29,9 @@ func profileCmd(args []string) {
verbose = flags.BoolP("verbose", "v", false, "Print the HTTP status and headers hefore the response body")
)
flags.SortFlags = false
flags.Parse(args)
if err := flags.Parse(args); err != nil {
exitWithError(err)
}

profile := flags.Arg(0)
cfg, err := broom.ReadConfig(".broom.yaml")
Expand Down
6 changes: 4 additions & 2 deletions cmd/broom/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import (
const rmDescription = `Remove a profile`

func rmCmd(args []string) {
flags := flag.NewFlagSet("rm", flag.ExitOnError)
flags := flag.NewFlagSet("rm", flag.ContinueOnError)
help := flags.BoolP("help", "h", false, "Display this help text and exit")
flags.SortFlags = false
flags.Parse(args)
if err := flags.Parse(args); err != nil {
exitWithError(err)
}
if *help || flags.NArg() < 2 {
rmUsage()
flagUsage(flags)
Expand Down

0 comments on commit 3598592

Please sign in to comment.