Skip to content

Commit

Permalink
Slightly better error handling and using flag.Arg(0) over os.Arg(0)
Browse files Browse the repository at this point in the history
  • Loading branch information
rpearce committed Oct 15, 2022
1 parent b71ff60 commit e0a6372
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,17 @@ func (s *StatusCommand) Run() error {
}

if s.cats {
browser.OpenURL(fmt.Sprint("https://http.cat/", status.code))
err := browser.OpenURL(fmt.Sprint("https://http.cat/", status.code))
if err != nil {
return err
}
}

if s.dogs {
browser.OpenURL(fmt.Sprint("https://httpstatusdogs.com/", status.code))
err := browser.OpenURL(fmt.Sprint("https://httpstatusdogs.com/", status.code))
if err != nil {
return err
}
}

return nil
Expand All @@ -430,18 +436,17 @@ func (s *StatusCommand) Run() error {
// =============================================================================

func root(args []string) error {
flag.Usage = usage

if len(args) < 1 {
return errors.New("httpwut: Please provide an HTTP status code")
}

flag.Usage = usage

if isAskingForHelp() {
usage()
return nil
}

subcommand := os.Args[1]
subcommand := flag.Arg(0)

if status, exists := statuses[subcommand]; exists {
cmd := NewStatusCommand(status)
Expand Down

0 comments on commit e0a6372

Please sign in to comment.