Skip to content

Commit

Permalink
Changed from arg to flag
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleimp committed Jul 31, 2020
1 parent 08cd721 commit c314b6f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
18 changes: 2 additions & 16 deletions cmd/cli/check.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package cli

import (
"errors"

"github.com/apex/log"
"github.com/urfave/cli/v2"
"github.com/wesleimp/unleash-checkr/internal/check"
Expand All @@ -12,30 +10,18 @@ import (

func runCheck(c *cli.Context) error {
expires := c.Int("expires")

url, err := checkArgs(c.Args())
if err != nil {
return err
}
url := c.String("url")

ctx := context.New(&config.Config{
URL: url,
Expires: expires,
})

_, err = check.Start(ctx)
_, err := check.Start(ctx)
if err != nil {
log.WithError(err).Error("Error checking flags")
return err
}

return nil
}

func checkArgs(args cli.Args) (string, error) {
if args.Len() == 0 {
return "", errors.New("check command requires exactly 1 argument. See --help")
}

return args.Get(0), nil
}
12 changes: 8 additions & 4 deletions cmd/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ func Run(version string, args []string) error {
Version: version,
Commands: []*cli.Command{
{
Name: "check",
Aliases: []string{"c"},
Usage: "checks the flags and print on the console",
ArgsUsage: "URL",
Name: "check",
Aliases: []string{"c"},
Usage: "checks the flags and print on the console",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "url",
Usage: "unleash api url",
Required: true,
},
&cli.IntFlag{
Name: "expires",
Aliases: []string{"e"},
Expand Down

0 comments on commit c314b6f

Please sign in to comment.