Skip to content

Commit

Permalink
output cli err
Browse files Browse the repository at this point in the history
  • Loading branch information
marwan-at-work committed Sep 4, 2018
1 parent 237e58a commit 9f01b9f
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions cmd/mod/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func main() {
Name: "upgrade",
Usage: "mod upgrade [-t]",
Description: "upgrade go.mod and imports one major or through -t",
Action: upgrade,
Action: withExit(upgrade),
Flags: []cli.Flag{
&cli.IntFlag{
Name: "tag",
Expand All @@ -31,13 +31,13 @@ func main() {
Name: "downgrade",
Usage: "mod downgrade",
Description: "downgrade go.mod and imports one major version",
Action: downgrade,
Action: withExit(downgrade),
},
{
Name: "migrate-deps",
Usage: "mod community-migrate -token=<github-token>",
Description: "migrate your +incompatiable dependencies to Go Modules",
Action: migrateDeps,
Action: withExit(migrateDeps),
Flags: []cli.Flag{
&cli.StringFlag{
Name: "token",
Expand Down Expand Up @@ -70,3 +70,17 @@ func downgrade(c *cli.Context) error {
func migrateDeps(c *cli.Context) error {
return migrate.Run(c.String("token"), c.Int("limit"), c.Bool("test"))
}

func withExit(f cli.ActionFunc) cli.ActionFunc {
return func(c *cli.Context) error {
return handleErr(f(c))
}
}

func handleErr(err error) error {
if err != nil {
return cli.Exit(err, 1)
}

return nil
}

0 comments on commit 9f01b9f

Please sign in to comment.