cloudflare/cloudflared

Public

mirrored from https://github.com/cloudflare/cloudflaredAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
a278753bbfddec4ef250fd1fb33d3d797c8ccda8

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

cmd/cloudflared/cliutil/errors.go

37lines · modecode

1package cliutil
2
3import (
4 "fmt"
5 "github.com/urfave/cli/v2"
6)
7
8type usageError string
9
10func (ue usageError) Error() string {
11 return string(ue)
12}
13
14func UsageError(format string, args ...interface{}) error {
15 if len(args) == 0 {
16 return usageError(format)
17 } else {
18 msg := fmt.Sprintf(format, args...)
19 return usageError(msg)
20 }
21}
22
23// Ensures exit with error code if actionFunc returns an error
24func ErrorHandler(actionFunc cli.ActionFunc) cli.ActionFunc {
25 return func(ctx *cli.Context) error {
26 err := actionFunc(ctx)
27 if err != nil {
28 if _, ok := err.(usageError); ok {
29 msg := fmt.Sprintf("%s\nSee 'cloudflared %s --help'.", err.Error(), ctx.Command.FullName())
30 err = cli.Exit(msg, -1)
31 } else if _, ok := err.(cli.ExitCoder); !ok {
32 err = cli.Exit(err.Error(), 1)
33 }
34 }
35 return err
36 }
37}
38