From 3216a7ea1485e4ee851852fc5f3f3e9aba29f159 Mon Sep 17 00:00:00 2001 From: Sascha Grunert Date: Thu, 5 Dec 2019 16:07:10 +0100 Subject: [PATCH] Switch to urfave/cli/v2 The latest release of the command line parser has some breaking changes which are included in this commit as well. Signed-off-by: Sascha Grunert --- cmd/crictl/attach.go | 19 +- cmd/crictl/completion.go | 8 +- cmd/crictl/config.go | 9 +- cmd/crictl/container.go | 152 ++++---- cmd/crictl/exec.go | 32 +- cmd/crictl/image.go | 85 ++--- cmd/crictl/info.go | 21 +- cmd/crictl/logs.go | 32 +- cmd/crictl/main.go | 65 ++-- cmd/crictl/portforward.go | 6 +- cmd/crictl/sandbox.go | 106 +++--- cmd/crictl/stats.go | 50 +-- cmd/crictl/util.go | 2 +- cmd/crictl/version.go | 4 +- go.mod | 2 +- go.sum | 5 +- vendor/github.com/urfave/cli/category.go | 44 --- vendor/github.com/urfave/cli/context.go | 339 ------------------ vendor/github.com/urfave/cli/flag_bool_t.go | 110 ------ .../github.com/urfave/cli/flag_int64_slice.go | 141 -------- .../github.com/urfave/cli/flag_int_slice.go | 142 -------- .../urfave/cli/flag_string_slice.go | 138 ------- vendor/github.com/urfave/cli/{ => v2}/.flake8 | 0 .../github.com/urfave/cli/{ => v2}/.gitignore | 0 .../urfave/cli/{ => v2}/.travis.yml | 5 +- .../urfave/cli/{ => v2}/CODE_OF_CONDUCT.md | 0 vendor/github.com/urfave/cli/{ => v2}/LICENSE | 0 .../github.com/urfave/cli/{ => v2}/README.md | 50 +-- vendor/github.com/urfave/cli/{ => v2}/app.go | 137 ++++--- .../urfave/cli/{ => v2}/appveyor.yml | 3 +- vendor/github.com/urfave/cli/v2/args.go | 54 +++ vendor/github.com/urfave/cli/v2/category.go | 78 ++++ vendor/github.com/urfave/cli/{ => v2}/cli.go | 17 +- .../github.com/urfave/cli/{ => v2}/command.go | 196 +++------- vendor/github.com/urfave/cli/v2/context.go | 281 +++++++++++++++ vendor/github.com/urfave/cli/{ => v2}/docs.go | 10 +- .../github.com/urfave/cli/{ => v2}/errors.go | 61 ++-- vendor/github.com/urfave/cli/{ => v2}/fish.go | 14 +- vendor/github.com/urfave/cli/{ => v2}/flag.go | 236 +++++++----- .../urfave/cli/{ => v2}/flag_bool.go | 83 +++-- .../urfave/cli/{ => v2}/flag_duration.go | 79 ++-- .../urfave/cli/{ => v2}/flag_float64.go | 78 ++-- .../urfave/cli/v2/flag_float64_slice.go | 165 +++++++++ .../urfave/cli/{ => v2}/flag_generic.go | 72 ++-- .../urfave/cli/{ => v2}/flag_int.go | 61 ++-- .../urfave/cli/{ => v2}/flag_int64.go | 63 ++-- .../urfave/cli/v2/flag_int64_slice.go | 161 +++++++++ .../urfave/cli/v2/flag_int_slice.go | 175 +++++++++ vendor/github.com/urfave/cli/v2/flag_path.go | 95 +++++ .../urfave/cli/{ => v2}/flag_string.go | 53 ++- .../urfave/cli/v2/flag_string_slice.go | 159 ++++++++ .../urfave/cli/{ => v2}/flag_uint.go | 63 ++-- .../urfave/cli/{ => v2}/flag_uint64.go | 73 ++-- .../github.com/urfave/cli/{ => v2}/funcs.go | 8 +- vendor/github.com/urfave/cli/{ => v2}/go.mod | 2 +- vendor/github.com/urfave/cli/{ => v2}/go.sum | 0 vendor/github.com/urfave/cli/{ => v2}/help.go | 47 +-- .../github.com/urfave/cli/{ => v2}/parse.go | 0 vendor/github.com/urfave/cli/{ => v2}/sort.go | 0 .../urfave/cli/{ => v2}/template.go | 7 +- vendor/modules.txt | 4 +- 61 files changed, 2196 insertions(+), 1906 deletions(-) delete mode 100644 vendor/github.com/urfave/cli/category.go delete mode 100644 vendor/github.com/urfave/cli/context.go delete mode 100644 vendor/github.com/urfave/cli/flag_bool_t.go delete mode 100644 vendor/github.com/urfave/cli/flag_int64_slice.go delete mode 100644 vendor/github.com/urfave/cli/flag_int_slice.go delete mode 100644 vendor/github.com/urfave/cli/flag_string_slice.go rename vendor/github.com/urfave/cli/{ => v2}/.flake8 (100%) rename vendor/github.com/urfave/cli/{ => v2}/.gitignore (100%) rename vendor/github.com/urfave/cli/{ => v2}/.travis.yml (79%) rename vendor/github.com/urfave/cli/{ => v2}/CODE_OF_CONDUCT.md (100%) rename vendor/github.com/urfave/cli/{ => v2}/LICENSE (100%) rename vendor/github.com/urfave/cli/{ => v2}/README.md (84%) rename vendor/github.com/urfave/cli/{ => v2}/app.go (83%) rename vendor/github.com/urfave/cli/{ => v2}/appveyor.yml (89%) create mode 100644 vendor/github.com/urfave/cli/v2/args.go create mode 100644 vendor/github.com/urfave/cli/v2/category.go rename vendor/github.com/urfave/cli/{ => v2}/cli.go (67%) rename vendor/github.com/urfave/cli/{ => v2}/command.go (57%) create mode 100644 vendor/github.com/urfave/cli/v2/context.go rename vendor/github.com/urfave/cli/{ => v2}/docs.go (93%) rename vendor/github.com/urfave/cli/{ => v2}/errors.go (63%) rename vendor/github.com/urfave/cli/{ => v2}/fish.go (93%) rename vendor/github.com/urfave/cli/{ => v2}/flag.go (55%) rename vendor/github.com/urfave/cli/{ => v2}/flag_bool.go (51%) rename vendor/github.com/urfave/cli/{ => v2}/flag_duration.go (56%) rename vendor/github.com/urfave/cli/{ => v2}/flag_float64.go (56%) create mode 100644 vendor/github.com/urfave/cli/v2/flag_float64_slice.go rename vendor/github.com/urfave/cli/{ => v2}/flag_generic.go (52%) rename vendor/github.com/urfave/cli/{ => v2}/flag_int.go (56%) rename vendor/github.com/urfave/cli/{ => v2}/flag_int64.go (56%) create mode 100644 vendor/github.com/urfave/cli/v2/flag_int64_slice.go create mode 100644 vendor/github.com/urfave/cli/v2/flag_int_slice.go create mode 100644 vendor/github.com/urfave/cli/v2/flag_path.go rename vendor/github.com/urfave/cli/{ => v2}/flag_string.go (59%) create mode 100644 vendor/github.com/urfave/cli/v2/flag_string_slice.go rename vendor/github.com/urfave/cli/{ => v2}/flag_uint.go (56%) rename vendor/github.com/urfave/cli/{ => v2}/flag_uint64.go (56%) rename vendor/github.com/urfave/cli/{ => v2}/funcs.go (88%) rename vendor/github.com/urfave/cli/{ => v2}/go.mod (82%) rename vendor/github.com/urfave/cli/{ => v2}/go.sum (100%) rename vendor/github.com/urfave/cli/{ => v2}/help.go (91%) rename vendor/github.com/urfave/cli/{ => v2}/parse.go (100%) rename vendor/github.com/urfave/cli/{ => v2}/sort.go (100%) rename vendor/github.com/urfave/cli/{ => v2}/template.go (98%) diff --git a/cmd/crictl/attach.go b/cmd/crictl/attach.go index 5b25ce0e08..154146cb69 100644 --- a/cmd/crictl/attach.go +++ b/cmd/crictl/attach.go @@ -21,25 +21,26 @@ import ( "net/url" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" "golang.org/x/net/context" pb "k8s.io/cri-api/pkg/apis/runtime/v1alpha2" ) -var runtimeAttachCommand = cli.Command{ +var runtimeAttachCommand = &cli.Command{ Name: "attach", Usage: "Attach to a running container", ArgsUsage: "CONTAINER-ID", - SkipArgReorder: true, UseShortOptionHandling: true, Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "tty,t", - Usage: "Allocate a pseudo-TTY", + &cli.BoolFlag{ + Name: "tty", + Aliases: []string{"t"}, + Usage: "Allocate a pseudo-TTY", }, - cli.BoolFlag{ - Name: "stdin,i", - Usage: "Keep STDIN open", + &cli.BoolFlag{ + Name: "stdin", + Aliases: []string{"i"}, + Usage: "Keep STDIN open", }, }, Action: func(context *cli.Context) error { diff --git a/cmd/crictl/completion.go b/cmd/crictl/completion.go index efb3562c65..79197585eb 100644 --- a/cmd/crictl/completion.go +++ b/cmd/crictl/completion.go @@ -20,7 +20,7 @@ import ( "fmt" "strings" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var bashCompletionTemplate = `_cli_bash_autocomplete() { @@ -47,7 +47,7 @@ func bashCompletion(c *cli.Context) error { for _, flag := range c.App.Flags { // only includes full flag name. - subcommands = append(subcommands, "--"+strings.Split(flag.GetName(), ",")[0]) + subcommands = append(subcommands, "--"+flag.Names()[0]) } fmt.Fprintln(c.App.Writer, fmt.Sprintf(bashCompletionTemplate, strings.Join(subcommands, "\n"))) @@ -83,7 +83,7 @@ func zshCompletion(c *cli.Context) error { opts := []string{} for _, flag := range c.App.Flags { // only includes full flag name. - opts = append(opts, "--"+strings.Split(flag.GetName(), ",")[0]) + opts = append(opts, "--"+flag.Names()[0]) } fmt.Fprintln(c.App.Writer, fmt.Sprintf(zshCompletionTemplate, strings.Join(subcommands, "' '"), strings.Join(opts, "' '"))) @@ -91,7 +91,7 @@ func zshCompletion(c *cli.Context) error { } -var completionCommand = cli.Command{ +var completionCommand = &cli.Command{ Name: "completion", Usage: "Output shell completion code", ArgsUsage: "SHELL", diff --git a/cmd/crictl/config.go b/cmd/crictl/config.go index 6fb45b9ed0..a3947cf9a8 100644 --- a/cmd/crictl/config.go +++ b/cmd/crictl/config.go @@ -24,7 +24,7 @@ import ( "strconv" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" "gopkg.in/yaml.v2" ) @@ -63,20 +63,19 @@ func writeConfig(c *Config, filepath string) error { return ioutil.WriteFile(filepath, data, 0644) } -var configCommand = cli.Command{ +var configCommand = &cli.Command{ Name: "config", Usage: "Get and set crictl options", ArgsUsage: "[]", - SkipArgReorder: true, UseShortOptionHandling: true, Flags: []cli.Flag{ - cli.StringFlag{ + &cli.StringFlag{ Name: "get", Usage: "get value: name", }, }, Action: func(context *cli.Context) error { - configFile := context.GlobalString("config") + configFile := context.String("config") if _, err := os.Stat(configFile); err != nil { if err := writeConfig(nil, configFile); err != nil { return err diff --git a/cmd/crictl/container.go b/cmd/crictl/container.go index 0b0c45e05a..76548ce362 100644 --- a/cmd/crictl/container.go +++ b/cmd/crictl/container.go @@ -27,7 +27,7 @@ import ( "github.com/docker/go-units" godigest "github.com/opencontainers/go-digest" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" "golang.org/x/net/context" pb "k8s.io/cri-api/pkg/apis/runtime/v1alpha2" ) @@ -73,30 +73,30 @@ type pullOptions struct { } var pullFlags = []cli.Flag{ - cli.BoolFlag{ + &cli.BoolFlag{ Name: "no-pull", Usage: "Do not pull the image on container creation", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "creds", Value: "", Usage: "Use `USERNAME[:PASSWORD]` for accessing the registry", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "auth", Value: "", Usage: "Use `AUTH_STRING` for accessing the registry. AUTH_STRING is a base64 encoded 'USERNAME[:PASSWORD]'", }, } -var createContainerCommand = cli.Command{ +var createContainerCommand = &cli.Command{ Name: "create", Usage: "Create a new container", ArgsUsage: "POD container-config.[json|yaml] pod-config.[json|yaml]", Flags: pullFlags, Action: func(context *cli.Context) error { - if len(context.Args()) != 3 { + if context.Args().Len() != 3 { return cli.ShowSubcommandHelp(context) } @@ -134,7 +134,7 @@ var createContainerCommand = cli.Command{ }, } -var startContainerCommand = cli.Command{ +var startContainerCommand = &cli.Command{ Name: "start", Usage: "Start one or more created containers", ArgsUsage: "CONTAINER-ID [CONTAINER-ID...]", @@ -159,32 +159,32 @@ var startContainerCommand = cli.Command{ }, } -var updateContainerCommand = cli.Command{ +var updateContainerCommand = &cli.Command{ Name: "update", Usage: "Update one or more running containers", ArgsUsage: "CONTAINER-ID [CONTAINER-ID...]", Flags: []cli.Flag{ - cli.Int64Flag{ + &cli.Int64Flag{ Name: "cpu-period", Usage: "CPU CFS period to be used for hardcapping (in usecs). 0 to use system default", }, - cli.Int64Flag{ + &cli.Int64Flag{ Name: "cpu-quota", Usage: "CPU CFS hardcap limit (in usecs). Allowed cpu time in a given period", }, - cli.Int64Flag{ + &cli.Int64Flag{ Name: "cpu-share", Usage: "CPU shares (relative weight vs. other containers)", }, - cli.Int64Flag{ + &cli.Int64Flag{ Name: "memory", Usage: "Memory limit (in bytes)", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "cpuset-cpus", Usage: "CPU(s) to use", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "cpuset-mems", Usage: "Memory node(s) to use", }, @@ -219,17 +219,17 @@ var updateContainerCommand = cli.Command{ }, } -var stopContainerCommand = cli.Command{ +var stopContainerCommand = &cli.Command{ Name: "stop", Usage: "Stop one or more running containers", ArgsUsage: "CONTAINER-ID [CONTAINER-ID...]", - SkipArgReorder: true, UseShortOptionHandling: true, Flags: []cli.Flag{ - cli.Int64Flag{ - Name: "timeout, t", - Value: 10, - Usage: "Seconds to wait to kill the container after a graceful stop is requested", + &cli.Int64Flag{ + Name: "timeout", + Aliases: []string{"t"}, + Value: 10, + Usage: "Seconds to wait to kill the container after a graceful stop is requested", }, }, Action: func(context *cli.Context) error { @@ -253,20 +253,21 @@ var stopContainerCommand = cli.Command{ }, } -var removeContainerCommand = cli.Command{ +var removeContainerCommand = &cli.Command{ Name: "rm", Usage: "Remove one or more containers", ArgsUsage: "CONTAINER-ID [CONTAINER-ID...]", - SkipArgReorder: true, UseShortOptionHandling: true, Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "force, f", - Usage: "Force removal of the container, disregarding if running", + &cli.BoolFlag{ + Name: "force", + Aliases: []string{"f"}, + Usage: "Force removal of the container, disregarding if running", }, - cli.BoolFlag{ - Name: "all, a", - Usage: "Remove all containers", + &cli.BoolFlag{ + Name: "all", + Aliases: []string{"a"}, + Usage: "Remove all containers", }, }, Action: func(ctx *cli.Context) error { @@ -276,7 +277,7 @@ var removeContainerCommand = cli.Command{ } defer closeConnection(ctx, runtimeConn) - ids := ctx.Args() + ids := ctx.Args().Slice() if ctx.Bool("all") { r, err := runtimeClient.ListContainers(context.Background(), &pb.ListContainersRequest{}) @@ -332,18 +333,20 @@ var removeContainerCommand = cli.Command{ }, } -var containerStatusCommand = cli.Command{ +var containerStatusCommand = &cli.Command{ Name: "inspect", Usage: "Display the status of one or more containers", ArgsUsage: "CONTAINER-ID [CONTAINER-ID...]", Flags: []cli.Flag{ - cli.StringFlag{ - Name: "output, o", - Usage: "Output format, One of: json|yaml|table", + &cli.StringFlag{ + Name: "output", + Aliases: []string{"o"}, + Usage: "Output format, One of: json|yaml|table", }, - cli.BoolFlag{ - Name: "quiet, q", - Usage: "Do not show verbose information", + &cli.BoolFlag{ + Name: "quiet", + Aliases: []string{"q"}, + Usage: "Do not show verbose information", }, }, Action: func(context *cli.Context) error { @@ -367,66 +370,72 @@ var containerStatusCommand = cli.Command{ }, } -var listContainersCommand = cli.Command{ +var listContainersCommand = &cli.Command{ Name: "ps", Usage: "List containers", - SkipArgReorder: true, UseShortOptionHandling: true, Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "verbose, v", - Usage: "Show verbose information for containers", + &cli.BoolFlag{ + Name: "verbose", + Aliases: []string{"v"}, + Usage: "Show verbose information for containers", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "id", Value: "", Usage: "Filter by container id", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "name", Value: "", Usage: "filter by container name regular expression pattern", }, - cli.StringFlag{ - Name: "pod, p", - Value: "", - Usage: "Filter by pod id", + &cli.StringFlag{ + Name: "pod", + Aliases: []string{"p"}, + Value: "", + Usage: "Filter by pod id", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "image", Value: "", Usage: "Filter by container image", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "state", Value: "", Usage: "Filter by container state", }, - cli.StringSliceFlag{ + &cli.StringSliceFlag{ Name: "label", Usage: "Filter by key=value label", }, - cli.BoolFlag{ - Name: "quiet, q", - Usage: "Only display container IDs", + &cli.BoolFlag{ + Name: "quiet", + Aliases: []string{"q"}, + Usage: "Only display container IDs", }, - cli.StringFlag{ - Name: "output, o", - Usage: "Output format, One of: json|yaml|table", + &cli.StringFlag{ + Name: "output", + Aliases: []string{"o"}, + Usage: "Output format, One of: json|yaml|table", }, - cli.BoolFlag{ - Name: "all, a", - Usage: "Show all containers", + &cli.BoolFlag{ + Name: "all", + Aliases: []string{"a"}, + Usage: "Show all containers", }, - cli.BoolFlag{ - Name: "latest, l", - Usage: "Show the most recently created container (includes all states)", + &cli.BoolFlag{ + Name: "latest", + Aliases: []string{"l"}, + Usage: "Show the most recently created container (includes all states)", }, - cli.IntFlag{ - Name: "last, n", - Usage: "Show last n recently created containers (includes all states). Set 0 for unlimited.", + &cli.IntFlag{ + Name: "last", + Aliases: []string{"n"}, + Usage: "Show last n recently created containers (includes all states). Set 0 for unlimited.", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "no-trunc", Usage: "Show output without truncating the ID", }, @@ -470,17 +479,18 @@ var listContainersCommand = cli.Command{ }, } -var runContainerCommand = cli.Command{ +var runContainerCommand = &cli.Command{ Name: "run", Usage: "Run a new container inside a sandbox", ArgsUsage: "container-config.[json|yaml] pod-config.[json|yaml]", - Flags: append(pullFlags, cli.StringFlag{ - Name: "runtime, r", - Usage: "Runtime handler to use. Available options are defined by the container runtime.", + Flags: append(pullFlags, &cli.StringFlag{ + Name: "runtime", + Aliases: []string{"r"}, + Usage: "Runtime handler to use. Available options are defined by the container runtime.", }), Action: func(context *cli.Context) error { - if len(context.Args()) != 2 { + if context.Args().Len() != 2 { return cli.ShowSubcommandHelp(context) } diff --git a/cmd/crictl/exec.go b/cmd/crictl/exec.go index e48ff6ec0c..aba515b637 100644 --- a/cmd/crictl/exec.go +++ b/cmd/crictl/exec.go @@ -22,7 +22,7 @@ import ( dockerterm "github.com/docker/docker/pkg/term" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" "golang.org/x/net/context" restclient "k8s.io/client-go/rest" remoteclient "k8s.io/client-go/tools/remotecommand" @@ -36,33 +36,35 @@ const ( kubeletURLHost = "http://127.0.0.1:10250" ) -var runtimeExecCommand = cli.Command{ +var runtimeExecCommand = &cli.Command{ Name: "exec", Usage: "Run a command in a running container", ArgsUsage: "CONTAINER-ID COMMAND [ARG...]", - SkipArgReorder: true, UseShortOptionHandling: true, Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "sync, s", - Usage: "Run the command synchronously", + &cli.BoolFlag{ + Name: "sync", + Aliases: []string{"s"}, + Usage: "Run the command synchronously", }, - cli.Int64Flag{ + &cli.Int64Flag{ Name: "timeout", Value: 0, Usage: "Timeout in seconds", }, - cli.BoolFlag{ - Name: "tty, t", - Usage: "Allocate a pseudo-TTY", + &cli.BoolFlag{ + Name: "tty", + Aliases: []string{"t"}, + Usage: "Allocate a pseudo-TTY", }, - cli.BoolFlag{ - Name: "interactive, i", - Usage: "Keep STDIN open", + &cli.BoolFlag{ + Name: "interactive", + Aliases: []string{"i"}, + Usage: "Keep STDIN open", }, }, Action: func(context *cli.Context) error { - if len(context.Args()) < 2 { + if context.Args().Len() < 2 { return cli.ShowSubcommandHelp(context) } @@ -77,7 +79,7 @@ var runtimeExecCommand = cli.Command{ timeout: context.Int64("timeout"), tty: context.Bool("tty"), stdin: context.Bool("interactive"), - cmd: context.Args()[1:], + cmd: context.Args().Slice()[1:], } if context.Bool("sync") { exitCode, err := ExecSync(runtimeClient, opts) diff --git a/cmd/crictl/image.go b/cmd/crictl/image.go index 4c206b5838..e4e5a3be75 100644 --- a/cmd/crictl/image.go +++ b/cmd/crictl/image.go @@ -24,7 +24,7 @@ import ( "github.com/docker/go-units" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" "golang.org/x/net/context" pb "k8s.io/cri-api/pkg/apis/runtime/v1alpha2" ) @@ -43,23 +43,22 @@ func (a imageByRef) Less(i, j int) bool { return a[i].Id < a[j].Id } -var pullImageCommand = cli.Command{ +var pullImageCommand = &cli.Command{ Name: "pull", Usage: "Pull an image from a registry", - SkipArgReorder: true, UseShortOptionHandling: true, Flags: []cli.Flag{ - cli.StringFlag{ + &cli.StringFlag{ Name: "creds", Value: "", Usage: "Use `USERNAME[:PASSWORD]` for accessing the registry", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "auth", Value: "", Usage: "Use `AUTH_STRING` for accessing the registry. AUTH_STRING is a base64 encoded 'USERNAME[:PASSWORD]'", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "pod-config", Value: "", Usage: "Use `pod-config.[json|yaml]` to override the the pull context", @@ -100,31 +99,33 @@ var pullImageCommand = cli.Command{ }, } -var listImageCommand = cli.Command{ +var listImageCommand = &cli.Command{ Name: "images", Aliases: []string{"image", "img"}, Usage: "List images", ArgsUsage: "[REPOSITORY[:TAG]]", - SkipArgReorder: true, UseShortOptionHandling: true, Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "verbose, v", - Usage: "Show verbose info for images", + &cli.BoolFlag{ + Name: "verbose", + Aliases: []string{"v"}, + Usage: "Show verbose info for images", }, - cli.BoolFlag{ - Name: "quiet, q", - Usage: "Only show image IDs", + &cli.BoolFlag{ + Name: "quiet", + Aliases: []string{"q"}, + Usage: "Only show image IDs", }, - cli.StringFlag{ - Name: "output, o", - Usage: "Output format, One of: json|yaml|table", + &cli.StringFlag{ + Name: "output", + Aliases: []string{"o"}, + Usage: "Output format, One of: json|yaml|table", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "digests", Usage: "Show digests", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "no-trunc", Usage: "Show output without truncating the ID", }, @@ -208,20 +209,21 @@ var listImageCommand = cli.Command{ }, } -var imageStatusCommand = cli.Command{ +var imageStatusCommand = &cli.Command{ Name: "inspecti", Usage: "Return the status of one or more images", ArgsUsage: "IMAGE-ID [IMAGE-ID...]", - SkipArgReorder: true, UseShortOptionHandling: true, Flags: []cli.Flag{ - cli.StringFlag{ - Name: "output, o", - Usage: "Output format, One of: json|yaml|table", + &cli.StringFlag{ + Name: "output", + Aliases: []string{"o"}, + Usage: "Output format, One of: json|yaml|table", }, - cli.BoolFlag{ - Name: "quiet, q", - Usage: "Do not show verbose information", + &cli.BoolFlag{ + Name: "quiet", + Aliases: []string{"q"}, + Usage: "Do not show verbose information", }, }, Action: func(context *cli.Context) error { @@ -285,20 +287,21 @@ var imageStatusCommand = cli.Command{ }, } -var removeImageCommand = cli.Command{ +var removeImageCommand = &cli.Command{ Name: "rmi", Usage: "Remove one or more images", ArgsUsage: "IMAGE-ID [IMAGE-ID...]", - SkipArgReorder: true, UseShortOptionHandling: true, Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "all, a", - Usage: "Remove all images", + &cli.BoolFlag{ + Name: "all", + Aliases: []string{"a"}, + Usage: "Remove all images", }, - cli.BoolFlag{ - Name: "prune, p", - Usage: "Remove all unused images", + &cli.BoolFlag{ + Name: "prune", + Aliases: []string{"q"}, + Usage: "Remove all unused images", }, }, Action: func(ctx *cli.Context) error { @@ -309,7 +312,7 @@ var removeImageCommand = cli.Command{ defer closeConnection(ctx, conn) ids := map[string]bool{} - for _, id := range ctx.Args() { + for _, id := range ctx.Args().Slice() { logrus.Debugf("User specified image to be removed: %v", id) ids[id] = true } @@ -406,15 +409,15 @@ var removeImageCommand = cli.Command{ }, } -var imageFsInfoCommand = cli.Command{ +var imageFsInfoCommand = &cli.Command{ Name: "imagefsinfo", Usage: "Return image filesystem info", - SkipArgReorder: true, UseShortOptionHandling: true, Flags: []cli.Flag{ - cli.StringFlag{ - Name: "output, o", - Usage: "Output format, One of: json|yaml|table", + &cli.StringFlag{ + Name: "output", + Aliases: []string{"o"}, + Usage: "Output format, One of: json|yaml|table", }, }, Action: func(context *cli.Context) error { diff --git a/cmd/crictl/info.go b/cmd/crictl/info.go index 212ac366ae..882380dfcb 100644 --- a/cmd/crictl/info.go +++ b/cmd/crictl/info.go @@ -20,26 +20,27 @@ import ( "fmt" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" "golang.org/x/net/context" pb "k8s.io/cri-api/pkg/apis/runtime/v1alpha2" ) -var runtimeStatusCommand = cli.Command{ +var runtimeStatusCommand = &cli.Command{ Name: "info", Usage: "Display information of the container runtime", ArgsUsage: "", - SkipArgReorder: true, UseShortOptionHandling: true, Flags: []cli.Flag{ - cli.StringFlag{ - Name: "output, o", - Value: "json", - Usage: "Output format, One of: json|yaml", + &cli.StringFlag{ + Name: "output", + Aliases: []string{"o"}, + Value: "json", + Usage: "Output format, One of: json|yaml", }, - cli.BoolFlag{ - Name: "quiet, q", - Usage: "Do not show verbose information", + &cli.BoolFlag{ + Name: "quiet", + Aliases: []string{"q"}, + Usage: "Do not show verbose information", }, }, Action: func(context *cli.Context) error { diff --git a/cmd/crictl/logs.go b/cmd/crictl/logs.go index ee17f54352..8b454ec897 100644 --- a/cmd/crictl/logs.go +++ b/cmd/crictl/logs.go @@ -24,45 +24,47 @@ import ( "time" timetypes "github.com/docker/docker/api/types/time" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/kubernetes/pkg/kubelet/kuberuntime/logs" ) -var logsCommand = cli.Command{ +var logsCommand = &cli.Command{ Name: "logs", Usage: "Fetch the logs of a container", ArgsUsage: "CONTAINER-ID", - SkipArgReorder: true, UseShortOptionHandling: true, Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "follow, f", - Usage: "Follow log output", + &cli.BoolFlag{ + Name: "follow", + Aliases: []string{"f"}, + Usage: "Follow log output", }, - cli.BoolFlag{ - Name: "previous, p", - Usage: "Print the logs for the previous instance of the container in a pod if it exists", + &cli.BoolFlag{ + Name: "previous", + Aliases: []string{"p"}, + Usage: "Print the logs for the previous instance of the container in a pod if it exists", }, - cli.Int64Flag{ + &cli.Int64Flag{ Name: "tail", Value: -1, Usage: "Number of lines to show from the end of the logs. Defaults to all", }, - cli.Int64Flag{ + &cli.Int64Flag{ Name: "limit-bytes", Value: -1, Usage: "Maximum bytes of logs to return. Defaults to no limit", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "since", Value: "", Usage: "Show logs since timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)", }, - cli.BoolFlag{ - Name: "timestamps, t", - Usage: "Show timestamps", + &cli.BoolFlag{ + Name: "timestamps", + Aliases: []string{"t"}, + Usage: "Show timestamps", }, }, Action: func(ctx *cli.Context) error { diff --git a/cmd/crictl/main.go b/cmd/crictl/main.go index 8db2526fbb..54e5056ac3 100644 --- a/cmd/crictl/main.go +++ b/cmd/crictl/main.go @@ -24,7 +24,7 @@ import ( "time" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" "google.golang.org/grpc" internalapi "k8s.io/cri-api/pkg/apis" "k8s.io/kubernetes/pkg/kubelet/remote" @@ -95,7 +95,7 @@ func main() { app.Usage = "client for CRI" app.Version = version.Version - app.Commands = []cli.Command{ + app.Commands = []*cli.Command{ runtimeAttachCommand, createContainerCommand, runtimeExecCommand, @@ -126,38 +126,43 @@ func main() { } app.Flags = []cli.Flag{ - cli.StringFlag{ - Name: "config, c", - EnvVar: "CRI_CONFIG_FILE", + &cli.StringFlag{ + Name: "config", + Aliases: []string{"c"}, + EnvVars: []string{"CRI_CONFIG_FILE"}, Value: defaultConfigPath, Usage: "Location of the client config file. If not specified and the default does not exist, the program's directory is searched as well", TakesFile: true, }, - cli.StringFlag{ - Name: "runtime-endpoint, r", - EnvVar: "CONTAINER_RUNTIME_ENDPOINT", - Value: defaultRuntimeEndpoint, - Usage: "Endpoint of CRI container runtime service", + &cli.StringFlag{ + Name: "runtime-endpoint", + Aliases: []string{"r"}, + EnvVars: []string{"CONTAINER_RUNTIME_ENDPOINT"}, + Value: defaultRuntimeEndpoint, + Usage: "Endpoint of CRI container runtime service", }, - cli.StringFlag{ - Name: "image-endpoint, i", - EnvVar: "IMAGE_SERVICE_ENDPOINT", - Usage: "Endpoint of CRI image manager service", + &cli.StringFlag{ + Name: "image-endpoint", + Aliases: []string{"i"}, + EnvVars: []string{"IMAGE_SERVICE_ENDPOINT"}, + Usage: "Endpoint of CRI image manager service", }, - cli.DurationFlag{ - Name: "timeout, t", - Value: defaultTimeout, - Usage: "Timeout of connecting to the server", + &cli.DurationFlag{ + Name: "timeout", + Aliases: []string{"t"}, + Value: defaultTimeout, + Usage: "Timeout of connecting to the server", }, - cli.BoolFlag{ - Name: "debug, D", - Usage: "Enable debug mode", + &cli.BoolFlag{ + Name: "debug", + Aliases: []string{"D"}, + Usage: "Enable debug mode", }, } app.Before = func(context *cli.Context) error { isUseConfig := false - configFile := context.GlobalString("config") + configFile := context.String("config") if _, err := os.Stat(configFile); err == nil { isUseConfig = true } else { @@ -181,10 +186,10 @@ func main() { } if !isUseConfig { - RuntimeEndpoint = context.GlobalString("runtime-endpoint") - ImageEndpoint = context.GlobalString("image-endpoint") - Timeout = context.GlobalDuration("timeout") - Debug = context.GlobalBool("debug") + RuntimeEndpoint = context.String("runtime-endpoint") + ImageEndpoint = context.String("image-endpoint") + Timeout = context.Duration("timeout") + Debug = context.Bool("debug") } else { // Get config from file. config, err := ReadConfig(configFile) @@ -198,24 +203,24 @@ func main() { } else if config.RuntimeEndpoint != "" { RuntimeEndpoint = config.RuntimeEndpoint } else { - RuntimeEndpoint = context.GlobalString("runtime-endpoint") + RuntimeEndpoint = context.String("runtime-endpoint") } if context.IsSet("image-endpoint") { ImageEndpoint = context.String("image-endpoint") } else if config.ImageEndpoint != "" { ImageEndpoint = config.ImageEndpoint } else { - ImageEndpoint = context.GlobalString("image-endpoint") + ImageEndpoint = context.String("image-endpoint") } if context.IsSet("timeout") { Timeout = context.Duration("timeout") } else if config.Timeout != 0 { Timeout = time.Duration(config.Timeout) * time.Second } else { - Timeout = context.GlobalDuration("timeout") + Timeout = context.Duration("timeout") } if context.IsSet("debug") { - Debug = context.GlobalBool("debug") + Debug = context.Bool("debug") } else { Debug = config.Debug } diff --git a/cmd/crictl/portforward.go b/cmd/crictl/portforward.go index efce7feec6..c8928030a3 100644 --- a/cmd/crictl/portforward.go +++ b/cmd/crictl/portforward.go @@ -24,7 +24,7 @@ import ( "os/signal" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" "golang.org/x/net/context" restclient "k8s.io/client-go/rest" portforward "k8s.io/client-go/tools/portforward" @@ -32,12 +32,12 @@ import ( pb "k8s.io/cri-api/pkg/apis/runtime/v1alpha2" ) -var runtimePortForwardCommand = cli.Command{ +var runtimePortForwardCommand = &cli.Command{ Name: "port-forward", Usage: "Forward local port to a pod", ArgsUsage: "POD-ID [LOCAL_PORT:]REMOTE_PORT", Action: func(context *cli.Context) error { - args := context.Args() + args := context.Args().Slice() if len(args) < 2 { return cli.ShowSubcommandHelp(context) } diff --git a/cmd/crictl/sandbox.go b/cmd/crictl/sandbox.go index 60adf1756d..d9907d9e9f 100644 --- a/cmd/crictl/sandbox.go +++ b/cmd/crictl/sandbox.go @@ -26,7 +26,7 @@ import ( "github.com/docker/go-units" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" "golang.org/x/net/context" pb "k8s.io/cri-api/pkg/apis/runtime/v1alpha2" @@ -40,14 +40,15 @@ func (a sandboxByCreated) Less(i, j int) bool { return a[i].CreatedAt > a[j].CreatedAt } -var runPodCommand = cli.Command{ +var runPodCommand = &cli.Command{ Name: "runp", Usage: "Run a new pod", ArgsUsage: "pod-config.[json|yaml]", Flags: []cli.Flag{ - cli.StringFlag{ - Name: "runtime, r", - Usage: "Runtime handler to use. Available options are defined by the container runtime.", + &cli.StringFlag{ + Name: "runtime", + Aliases: []string{"r"}, + Usage: "Runtime handler to use. Available options are defined by the container runtime.", }, }, @@ -78,7 +79,7 @@ var runPodCommand = cli.Command{ }, } -var stopPodCommand = cli.Command{ +var stopPodCommand = &cli.Command{ Name: "stopp", Usage: "Stop one or more running pods", ArgsUsage: "POD-ID [POD-ID...]", @@ -102,20 +103,21 @@ var stopPodCommand = cli.Command{ }, } -var removePodCommand = cli.Command{ +var removePodCommand = &cli.Command{ Name: "rmp", Usage: "Remove one or more pods", ArgsUsage: "POD-ID [POD-ID...]", - SkipArgReorder: true, UseShortOptionHandling: true, Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "force, f", - Usage: "Force removal of the pod sandbox, disregarding if running", + &cli.BoolFlag{ + Name: "force", + Aliases: []string{"f"}, + Usage: "Force removal of the pod sandbox, disregarding if running", }, - cli.BoolFlag{ - Name: "all, a", - Usage: "Remove all pods", + &cli.BoolFlag{ + Name: "all", + Aliases: []string{"a"}, + Usage: "Remove all pods", }, }, Action: func(ctx *cli.Context) error { @@ -125,7 +127,7 @@ var removePodCommand = cli.Command{ } defer closeConnection(ctx, runtimeConn) - ids := ctx.Args() + ids := ctx.Args().Slice() if ctx.Bool("all") { r, err := runtimeClient.ListPodSandbox(context.Background(), &pb.ListPodSandboxRequest{}) @@ -180,20 +182,21 @@ var removePodCommand = cli.Command{ }, } -var podStatusCommand = cli.Command{ +var podStatusCommand = &cli.Command{ Name: "inspectp", Usage: "Display the status of one or more pods", ArgsUsage: "POD-ID [POD-ID...]", - SkipArgReorder: true, UseShortOptionHandling: true, Flags: []cli.Flag{ - cli.StringFlag{ - Name: "output, o", - Usage: "Output format, One of: json|yaml|table", + &cli.StringFlag{ + Name: "output", + Aliases: []string{"o"}, + Usage: "Output format, One of: json|yaml|table", }, - cli.BoolFlag{ - Name: "quiet, q", - Usage: "Do not show verbose information", + &cli.BoolFlag{ + Name: "quiet", + Aliases: []string{"q"}, + Usage: "Do not show verbose information", }, }, Action: func(context *cli.Context) error { @@ -217,57 +220,62 @@ var podStatusCommand = cli.Command{ }, } -var listPodCommand = cli.Command{ +var listPodCommand = &cli.Command{ Name: "pods", Usage: "List pods", - SkipArgReorder: true, UseShortOptionHandling: true, Flags: []cli.Flag{ - cli.StringFlag{ + &cli.StringFlag{ Name: "id", Value: "", Usage: "filter by pod id", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "name", Value: "", Usage: "filter by pod name regular expression pattern", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "namespace", Value: "", Usage: "filter by pod namespace regular expression pattern", }, - cli.StringFlag{ - Name: "state, s", - Value: "", - Usage: "filter by pod state", + &cli.StringFlag{ + Name: "state", + Aliases: []string{"s"}, + Value: "", + Usage: "filter by pod state", }, - cli.StringSliceFlag{ + &cli.StringSliceFlag{ Name: "label", Usage: "filter by key=value label", }, - cli.BoolFlag{ - Name: "verbose, v", - Usage: "show verbose info for pods", + &cli.BoolFlag{ + Name: "verbose", + Aliases: []string{"v"}, + Usage: "show verbose info for pods", }, - cli.BoolFlag{ - Name: "quiet, q", - Usage: "list only pod IDs", + &cli.BoolFlag{ + Name: "quiet", + Aliases: []string{"q"}, + Usage: "list only pod IDs", }, - cli.StringFlag{ - Name: "output, o", - Usage: "Output format, One of: json|yaml|table", + &cli.StringFlag{ + Name: "output", + Aliases: []string{"o"}, + Usage: "Output format, One of: json|yaml|table", }, - cli.BoolFlag{ - Name: "latest, l", - Usage: "Show the most recently created pod", + &cli.BoolFlag{ + Name: "latest", + Aliases: []string{"l"}, + Usage: "Show the most recently created pod", }, - cli.IntFlag{ - Name: "last, n", - Usage: "Show last n recently created pods. Set 0 for unlimited", + &cli.IntFlag{ + Name: "last", + Aliases: []string{"n"}, + Usage: "Show last n recently created pods. Set 0 for unlimited", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "no-trunc", Usage: "Show output without truncating the ID", }, diff --git a/cmd/crictl/stats.go b/cmd/crictl/stats.go index adb19a5414..42fb067e5c 100644 --- a/cmd/crictl/stats.go +++ b/cmd/crictl/stats.go @@ -23,7 +23,7 @@ import ( "github.com/docker/go-units" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" "golang.org/x/net/context" pb "k8s.io/cri-api/pkg/apis/runtime/v1alpha2" ) @@ -45,43 +45,47 @@ type statsOptions struct { watch bool } -var statsCommand = cli.Command{ +var statsCommand = &cli.Command{ Name: "stats", Usage: "List container(s) resource usage statistics", - SkipArgReorder: true, UseShortOptionHandling: true, ArgsUsage: "[ID]", Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "all, a", - Usage: "Show all containers (default shows just running)", + &cli.BoolFlag{ + Name: "all", + Aliases: []string{"a"}, + Usage: "Show all containers (default shows just running)", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "id", Value: "", Usage: "Filter by container id", }, - cli.StringFlag{ - Name: "pod, p", - Value: "", - Usage: "Filter by pod id", + &cli.StringFlag{ + Name: "pod", + Aliases: []string{"p"}, + Value: "", + Usage: "Filter by pod id", }, - cli.StringSliceFlag{ + &cli.StringSliceFlag{ Name: "label", Usage: "Filter by key=value label", }, - cli.StringFlag{ - Name: "output, o", - Usage: "Output format, One of: json|yaml|table", + &cli.StringFlag{ + Name: "output", + Aliases: []string{"o"}, + Usage: "Output format, One of: json|yaml|table", }, - cli.IntFlag{ - Name: "seconds, s", - Value: 1, - Usage: "Sample duration for CPU usage in seconds", + &cli.IntFlag{ + Name: "seconds", + Aliases: []string{"s"}, + Value: 1, + Usage: "Sample duration for CPU usage in seconds", }, - cli.BoolFlag{ - Name: "watch, w", - Usage: "Watch pod resources", + &cli.BoolFlag{ + Name: "watch", + Aliases: []string{"w"}, + Usage: "Watch pod resources", }, }, Action: func(context *cli.Context) error { @@ -93,7 +97,7 @@ var statsCommand = cli.Command{ id := context.String("id") if id == "" && context.NArg() > 0 { - id = context.Args()[0] + id = context.Args().Get(0) } opts := statsOptions{ diff --git a/cmd/crictl/util.go b/cmd/crictl/util.go index 31b7a46359..dd782efd12 100644 --- a/cmd/crictl/util.go +++ b/cmd/crictl/util.go @@ -29,7 +29,7 @@ import ( "github.com/ghodss/yaml" "github.com/golang/protobuf/jsonpb" "github.com/golang/protobuf/proto" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" "google.golang.org/grpc" utilyaml "k8s.io/apimachinery/pkg/util/yaml" pb "k8s.io/cri-api/pkg/apis/runtime/v1alpha2" diff --git a/cmd/crictl/version.go b/cmd/crictl/version.go index 8d582d5de8..3a5b2ca810 100644 --- a/cmd/crictl/version.go +++ b/cmd/crictl/version.go @@ -20,7 +20,7 @@ import ( "fmt" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" "golang.org/x/net/context" pb "k8s.io/cri-api/pkg/apis/runtime/v1alpha2" ) @@ -29,7 +29,7 @@ const ( criClientVersion = "v1alpha2" ) -var runtimeVersionCommand = cli.Command{ +var runtimeVersionCommand = &cli.Command{ Name: "version", Usage: "Display runtime version information", Action: func(context *cli.Context) error { diff --git a/go.mod b/go.mod index 35347f91dd..b6009272c7 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/opencontainers/selinux v1.3.1-0.20190929122143-5215b1806f52 github.com/pborman/uuid v1.2.0 github.com/sirupsen/logrus v1.4.2 - github.com/urfave/cli v1.22.2 + github.com/urfave/cli/v2 v2.0.0 golang.org/x/net v0.0.0-20191204025024-5ee1b9f4859a golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e google.golang.org/grpc v1.25.1 diff --git a/go.sum b/go.sum index 6b3b385d3b..b7d6bedfe3 100644 --- a/go.sum +++ b/go.sum @@ -506,9 +506,10 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1 github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/ultraware/funlen v0.0.1/go.mod h1:Dp4UiAus7Wdb9KUZsYWZEWiRzGuM2kXM1lPbfaF6xhA= github.com/ultraware/funlen v0.0.2/go.mod h1:Dp4UiAus7Wdb9KUZsYWZEWiRzGuM2kXM1lPbfaF6xhA= +github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= -github.com/urfave/cli v1.22.2 h1:gsqYFH8bb9ekPA12kRo0hfjngWQjkJPlN9R0N78BoUo= -github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= +github.com/urfave/cli/v2 v2.0.0 h1:+HU9SCbu8GnEUFtIBfuUNXN39ofWViIEJIp6SURMpCg= +github.com/urfave/cli/v2 v2.0.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.2.0/go.mod h1:4vX61m6KN+xDduDNwXrhIAVZaZaZiQ1luJk8LWSxF3s= diff --git a/vendor/github.com/urfave/cli/category.go b/vendor/github.com/urfave/cli/category.go deleted file mode 100644 index bf3c73c55e..0000000000 --- a/vendor/github.com/urfave/cli/category.go +++ /dev/null @@ -1,44 +0,0 @@ -package cli - -// CommandCategories is a slice of *CommandCategory. -type CommandCategories []*CommandCategory - -// CommandCategory is a category containing commands. -type CommandCategory struct { - Name string - Commands Commands -} - -func (c CommandCategories) Less(i, j int) bool { - return lexicographicLess(c[i].Name, c[j].Name) -} - -func (c CommandCategories) Len() int { - return len(c) -} - -func (c CommandCategories) Swap(i, j int) { - c[i], c[j] = c[j], c[i] -} - -// AddCommand adds a command to a category. -func (c CommandCategories) AddCommand(category string, command Command) CommandCategories { - for _, commandCategory := range c { - if commandCategory.Name == category { - commandCategory.Commands = append(commandCategory.Commands, command) - return c - } - } - return append(c, &CommandCategory{Name: category, Commands: []Command{command}}) -} - -// VisibleCommands returns a slice of the Commands with Hidden=false -func (c *CommandCategory) VisibleCommands() []Command { - ret := []Command{} - for _, command := range c.Commands { - if !command.Hidden { - ret = append(ret, command) - } - } - return ret -} diff --git a/vendor/github.com/urfave/cli/context.go b/vendor/github.com/urfave/cli/context.go deleted file mode 100644 index ecfc032821..0000000000 --- a/vendor/github.com/urfave/cli/context.go +++ /dev/null @@ -1,339 +0,0 @@ -package cli - -import ( - "errors" - "flag" - "fmt" - "os" - "reflect" - "strings" - "syscall" -) - -// Context is a type that is passed through to -// each Handler action in a cli application. Context -// can be used to retrieve context-specific Args and -// parsed command-line options. -type Context struct { - App *App - Command Command - shellComplete bool - flagSet *flag.FlagSet - setFlags map[string]bool - parentContext *Context -} - -// NewContext creates a new context. For use in when invoking an App or Command action. -func NewContext(app *App, set *flag.FlagSet, parentCtx *Context) *Context { - c := &Context{App: app, flagSet: set, parentContext: parentCtx} - - if parentCtx != nil { - c.shellComplete = parentCtx.shellComplete - } - - return c -} - -// NumFlags returns the number of flags set -func (c *Context) NumFlags() int { - return c.flagSet.NFlag() -} - -// Set sets a context flag to a value. -func (c *Context) Set(name, value string) error { - c.setFlags = nil - return c.flagSet.Set(name, value) -} - -// GlobalSet sets a context flag to a value on the global flagset -func (c *Context) GlobalSet(name, value string) error { - globalContext(c).setFlags = nil - return globalContext(c).flagSet.Set(name, value) -} - -// IsSet determines if the flag was actually set -func (c *Context) IsSet(name string) bool { - if c.setFlags == nil { - c.setFlags = make(map[string]bool) - - c.flagSet.Visit(func(f *flag.Flag) { - c.setFlags[f.Name] = true - }) - - c.flagSet.VisitAll(func(f *flag.Flag) { - if _, ok := c.setFlags[f.Name]; ok { - return - } - c.setFlags[f.Name] = false - }) - - // XXX hack to support IsSet for flags with EnvVar - // - // There isn't an easy way to do this with the current implementation since - // whether a flag was set via an environment variable is very difficult to - // determine here. Instead, we intend to introduce a backwards incompatible - // change in version 2 to add `IsSet` to the Flag interface to push the - // responsibility closer to where the information required to determine - // whether a flag is set by non-standard means such as environment - // variables is available. - // - // See https://github.com/urfave/cli/issues/294 for additional discussion - flags := c.Command.Flags - if c.Command.Name == "" { // cannot == Command{} since it contains slice types - if c.App != nil { - flags = c.App.Flags - } - } - for _, f := range flags { - eachName(f.GetName(), func(name string) { - if isSet, ok := c.setFlags[name]; isSet || !ok { - return - } - - val := reflect.ValueOf(f) - if val.Kind() == reflect.Ptr { - val = val.Elem() - } - - filePathValue := val.FieldByName("FilePath") - if filePathValue.IsValid() { - eachName(filePathValue.String(), func(filePath string) { - if _, err := os.Stat(filePath); err == nil { - c.setFlags[name] = true - return - } - }) - } - - envVarValue := val.FieldByName("EnvVar") - if envVarValue.IsValid() { - eachName(envVarValue.String(), func(envVar string) { - envVar = strings.TrimSpace(envVar) - if _, ok := syscall.Getenv(envVar); ok { - c.setFlags[name] = true - return - } - }) - } - }) - } - } - - return c.setFlags[name] -} - -// GlobalIsSet determines if the global flag was actually set -func (c *Context) GlobalIsSet(name string) bool { - ctx := c - if ctx.parentContext != nil { - ctx = ctx.parentContext - } - - for ; ctx != nil; ctx = ctx.parentContext { - if ctx.IsSet(name) { - return true - } - } - return false -} - -// FlagNames returns a slice of flag names used in this context. -func (c *Context) FlagNames() (names []string) { - for _, f := range c.Command.Flags { - name := strings.Split(f.GetName(), ",")[0] - if name == "help" { - continue - } - names = append(names, name) - } - return -} - -// GlobalFlagNames returns a slice of global flag names used by the app. -func (c *Context) GlobalFlagNames() (names []string) { - for _, f := range c.App.Flags { - name := strings.Split(f.GetName(), ",")[0] - if name == "help" || name == "version" { - continue - } - names = append(names, name) - } - return -} - -// Parent returns the parent context, if any -func (c *Context) Parent() *Context { - return c.parentContext -} - -// value returns the value of the flag coressponding to `name` -func (c *Context) value(name string) interface{} { - return c.flagSet.Lookup(name).Value.(flag.Getter).Get() -} - -// Args contains apps console arguments -type Args []string - -// Args returns the command line arguments associated with the context. -func (c *Context) Args() Args { - args := Args(c.flagSet.Args()) - return args -} - -// NArg returns the number of the command line arguments. -func (c *Context) NArg() int { - return len(c.Args()) -} - -// Get returns the nth argument, or else a blank string -func (a Args) Get(n int) string { - if len(a) > n { - return a[n] - } - return "" -} - -// First returns the first argument, or else a blank string -func (a Args) First() string { - return a.Get(0) -} - -// Tail returns the rest of the arguments (not the first one) -// or else an empty string slice -func (a Args) Tail() []string { - if len(a) >= 2 { - return []string(a)[1:] - } - return []string{} -} - -// Present checks if there are any arguments present -func (a Args) Present() bool { - return len(a) != 0 -} - -// Swap swaps arguments at the given indexes -func (a Args) Swap(from, to int) error { - if from >= len(a) || to >= len(a) { - return errors.New("index out of range") - } - a[from], a[to] = a[to], a[from] - return nil -} - -func globalContext(ctx *Context) *Context { - if ctx == nil { - return nil - } - - for { - if ctx.parentContext == nil { - return ctx - } - ctx = ctx.parentContext - } -} - -func lookupGlobalFlagSet(name string, ctx *Context) *flag.FlagSet { - if ctx.parentContext != nil { - ctx = ctx.parentContext - } - for ; ctx != nil; ctx = ctx.parentContext { - if f := ctx.flagSet.Lookup(name); f != nil { - return ctx.flagSet - } - } - return nil -} - -func copyFlag(name string, ff *flag.Flag, set *flag.FlagSet) { - switch ff.Value.(type) { - case *StringSlice: - default: - _ = set.Set(name, ff.Value.String()) - } -} - -func normalizeFlags(flags []Flag, set *flag.FlagSet) error { - visited := make(map[string]bool) - set.Visit(func(f *flag.Flag) { - visited[f.Name] = true - }) - for _, f := range flags { - parts := strings.Split(f.GetName(), ",") - if len(parts) == 1 { - continue - } - var ff *flag.Flag - for _, name := range parts { - name = strings.Trim(name, " ") - if visited[name] { - if ff != nil { - return errors.New("Cannot use two forms of the same flag: " + name + " " + ff.Name) - } - ff = set.Lookup(name) - } - } - if ff == nil { - continue - } - for _, name := range parts { - name = strings.Trim(name, " ") - if !visited[name] { - copyFlag(name, ff, set) - } - } - } - return nil -} - -type requiredFlagsErr interface { - error - getMissingFlags() []string -} - -type errRequiredFlags struct { - missingFlags []string -} - -func (e *errRequiredFlags) Error() string { - numberOfMissingFlags := len(e.missingFlags) - if numberOfMissingFlags == 1 { - return fmt.Sprintf("Required flag %q not set", e.missingFlags[0]) - } - joinedMissingFlags := strings.Join(e.missingFlags, ", ") - return fmt.Sprintf("Required flags %q not set", joinedMissingFlags) -} - -func (e *errRequiredFlags) getMissingFlags() []string { - return e.missingFlags -} - -func checkRequiredFlags(flags []Flag, context *Context) requiredFlagsErr { - var missingFlags []string - for _, f := range flags { - if rf, ok := f.(RequiredFlag); ok && rf.IsRequired() { - var flagPresent bool - var flagName string - for _, key := range strings.Split(f.GetName(), ",") { - if len(key) > 1 { - flagName = key - } - - if context.IsSet(strings.TrimSpace(key)) { - flagPresent = true - } - } - - if !flagPresent && flagName != "" { - missingFlags = append(missingFlags, flagName) - } - } - } - - if len(missingFlags) != 0 { - return &errRequiredFlags{missingFlags: missingFlags} - } - - return nil -} diff --git a/vendor/github.com/urfave/cli/flag_bool_t.go b/vendor/github.com/urfave/cli/flag_bool_t.go deleted file mode 100644 index cd0888fa21..0000000000 --- a/vendor/github.com/urfave/cli/flag_bool_t.go +++ /dev/null @@ -1,110 +0,0 @@ -package cli - -import ( - "flag" - "fmt" - "strconv" -) - -// BoolTFlag is a flag with type bool that is true by default -type BoolTFlag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - Destination *bool -} - -// String returns a readable representation of this value -// (for usage defaults) -func (f BoolTFlag) String() string { - return FlagStringer(f) -} - -// GetName returns the name of the flag -func (f BoolTFlag) GetName() string { - return f.Name -} - -// IsRequired returns whether or not the flag is required -func (f BoolTFlag) IsRequired() bool { - return f.Required -} - -// TakesValue returns true of the flag takes a value, otherwise false -func (f BoolTFlag) TakesValue() bool { - return false -} - -// GetUsage returns the usage string for the flag -func (f BoolTFlag) GetUsage() string { - return f.Usage -} - -// GetValue returns the flags value as string representation and an empty -// string if the flag takes no value at all. -func (f BoolTFlag) GetValue() string { - return "" -} - -// BoolT looks up the value of a local BoolTFlag, returns -// false if not found -func (c *Context) BoolT(name string) bool { - return lookupBoolT(name, c.flagSet) -} - -// GlobalBoolT looks up the value of a global BoolTFlag, returns -// false if not found -func (c *Context) GlobalBoolT(name string) bool { - if fs := lookupGlobalFlagSet(name, c); fs != nil { - return lookupBoolT(name, fs) - } - return false -} - -// Apply populates the flag given the flag set and environment -// Ignores errors -func (f BoolTFlag) Apply(set *flag.FlagSet) { - _ = f.ApplyWithError(set) -} - -// ApplyWithError populates the flag given the flag set and environment -func (f BoolTFlag) ApplyWithError(set *flag.FlagSet) error { - val := true - - if envVal, ok := flagFromFileEnv(f.FilePath, f.EnvVar); ok { - if envVal == "" { - val = false - } else { - envValBool, err := strconv.ParseBool(envVal) - if err != nil { - return fmt.Errorf("could not parse %s as bool value for flag %s: %s", envVal, f.Name, err) - } - val = envValBool - } - } - - eachName(f.Name, func(name string) { - if f.Destination != nil { - set.BoolVar(f.Destination, name, val, f.Usage) - return - } - set.Bool(name, val, f.Usage) - }) - - return nil -} - -func lookupBoolT(name string, set *flag.FlagSet) bool { - f := set.Lookup(name) - if f != nil { - parsed, err := strconv.ParseBool(f.Value.String()) - if err != nil { - return false - } - return parsed - } - return false -} diff --git a/vendor/github.com/urfave/cli/flag_int64_slice.go b/vendor/github.com/urfave/cli/flag_int64_slice.go deleted file mode 100644 index ed2e983b62..0000000000 --- a/vendor/github.com/urfave/cli/flag_int64_slice.go +++ /dev/null @@ -1,141 +0,0 @@ -package cli - -import ( - "flag" - "fmt" - "strconv" - "strings" -) - -// Int64Slice is an opaque type for []int to satisfy flag.Value and flag.Getter -type Int64Slice []int64 - -// Set parses the value into an integer and appends it to the list of values -func (f *Int64Slice) Set(value string) error { - tmp, err := strconv.ParseInt(value, 10, 64) - if err != nil { - return err - } - *f = append(*f, tmp) - return nil -} - -// String returns a readable representation of this value (for usage defaults) -func (f *Int64Slice) String() string { - return fmt.Sprintf("%#v", *f) -} - -// Value returns the slice of ints set by this flag -func (f *Int64Slice) Value() []int64 { - return *f -} - -// Get returns the slice of ints set by this flag -func (f *Int64Slice) Get() interface{} { - return *f -} - -// Int64SliceFlag is a flag with type *Int64Slice -type Int64SliceFlag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - Value *Int64Slice -} - -// String returns a readable representation of this value -// (for usage defaults) -func (f Int64SliceFlag) String() string { - return FlagStringer(f) -} - -// GetName returns the name of the flag -func (f Int64SliceFlag) GetName() string { - return f.Name -} - -// IsRequired returns whether or not the flag is required -func (f Int64SliceFlag) IsRequired() bool { - return f.Required -} - -// TakesValue returns true of the flag takes a value, otherwise false -func (f Int64SliceFlag) TakesValue() bool { - return true -} - -// GetUsage returns the usage string for the flag -func (f Int64SliceFlag) GetUsage() string { - return f.Usage -} - -// GetValue returns the flags value as string representation and an empty -// string if the flag takes no value at all. -func (f Int64SliceFlag) GetValue() string { - if f.Value != nil { - return f.Value.String() - } - return "" -} - -// Apply populates the flag given the flag set and environment -// Ignores errors -func (f Int64SliceFlag) Apply(set *flag.FlagSet) { - _ = f.ApplyWithError(set) -} - -// ApplyWithError populates the flag given the flag set and environment -func (f Int64SliceFlag) ApplyWithError(set *flag.FlagSet) error { - if envVal, ok := flagFromFileEnv(f.FilePath, f.EnvVar); ok { - newVal := &Int64Slice{} - for _, s := range strings.Split(envVal, ",") { - s = strings.TrimSpace(s) - if err := newVal.Set(s); err != nil { - return fmt.Errorf("could not parse %s as int64 slice value for flag %s: %s", envVal, f.Name, err) - } - } - if f.Value == nil { - f.Value = newVal - } else { - *f.Value = *newVal - } - } - - eachName(f.Name, func(name string) { - if f.Value == nil { - f.Value = &Int64Slice{} - } - set.Var(f.Value, name, f.Usage) - }) - return nil -} - -// Int64Slice looks up the value of a local Int64SliceFlag, returns -// nil if not found -func (c *Context) Int64Slice(name string) []int64 { - return lookupInt64Slice(name, c.flagSet) -} - -// GlobalInt64Slice looks up the value of a global Int64SliceFlag, returns -// nil if not found -func (c *Context) GlobalInt64Slice(name string) []int64 { - if fs := lookupGlobalFlagSet(name, c); fs != nil { - return lookupInt64Slice(name, fs) - } - return nil -} - -func lookupInt64Slice(name string, set *flag.FlagSet) []int64 { - f := set.Lookup(name) - if f != nil { - parsed, err := (f.Value.(*Int64Slice)).Value(), error(nil) - if err != nil { - return nil - } - return parsed - } - return nil -} diff --git a/vendor/github.com/urfave/cli/flag_int_slice.go b/vendor/github.com/urfave/cli/flag_int_slice.go deleted file mode 100644 index c38d010fd0..0000000000 --- a/vendor/github.com/urfave/cli/flag_int_slice.go +++ /dev/null @@ -1,142 +0,0 @@ -package cli - -import ( - "flag" - "fmt" - "strconv" - "strings" -) - -// IntSlice is an opaque type for []int to satisfy flag.Value and flag.Getter -type IntSlice []int - -// Set parses the value into an integer and appends it to the list of values -func (f *IntSlice) Set(value string) error { - tmp, err := strconv.Atoi(value) - if err != nil { - return err - } - *f = append(*f, tmp) - return nil -} - -// String returns a readable representation of this value (for usage defaults) -func (f *IntSlice) String() string { - return fmt.Sprintf("%#v", *f) -} - -// Value returns the slice of ints set by this flag -func (f *IntSlice) Value() []int { - return *f -} - -// Get returns the slice of ints set by this flag -func (f *IntSlice) Get() interface{} { - return *f -} - -// IntSliceFlag is a flag with type *IntSlice -type IntSliceFlag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - Value *IntSlice -} - -// String returns a readable representation of this value -// (for usage defaults) -func (f IntSliceFlag) String() string { - return FlagStringer(f) -} - -// GetName returns the name of the flag -func (f IntSliceFlag) GetName() string { - return f.Name -} - -// IsRequired returns whether or not the flag is required -func (f IntSliceFlag) IsRequired() bool { - return f.Required -} - -// TakesValue returns true of the flag takes a value, otherwise false -func (f IntSliceFlag) TakesValue() bool { - return true -} - -// GetUsage returns the usage string for the flag -func (f IntSliceFlag) GetUsage() string { - return f.Usage -} - -// GetValue returns the flags value as string representation and an empty -// string if the flag takes no value at all. -func (f IntSliceFlag) GetValue() string { - if f.Value != nil { - return f.Value.String() - } - return "" -} - -// Apply populates the flag given the flag set and environment -// Ignores errors -func (f IntSliceFlag) Apply(set *flag.FlagSet) { - _ = f.ApplyWithError(set) -} - -// ApplyWithError populates the flag given the flag set and environment -func (f IntSliceFlag) ApplyWithError(set *flag.FlagSet) error { - if envVal, ok := flagFromFileEnv(f.FilePath, f.EnvVar); ok { - newVal := &IntSlice{} - for _, s := range strings.Split(envVal, ",") { - s = strings.TrimSpace(s) - if err := newVal.Set(s); err != nil { - return fmt.Errorf("could not parse %s as int slice value for flag %s: %s", envVal, f.Name, err) - } - } - if f.Value == nil { - f.Value = newVal - } else { - *f.Value = *newVal - } - } - - eachName(f.Name, func(name string) { - if f.Value == nil { - f.Value = &IntSlice{} - } - set.Var(f.Value, name, f.Usage) - }) - - return nil -} - -// IntSlice looks up the value of a local IntSliceFlag, returns -// nil if not found -func (c *Context) IntSlice(name string) []int { - return lookupIntSlice(name, c.flagSet) -} - -// GlobalIntSlice looks up the value of a global IntSliceFlag, returns -// nil if not found -func (c *Context) GlobalIntSlice(name string) []int { - if fs := lookupGlobalFlagSet(name, c); fs != nil { - return lookupIntSlice(name, fs) - } - return nil -} - -func lookupIntSlice(name string, set *flag.FlagSet) []int { - f := set.Lookup(name) - if f != nil { - parsed, err := (f.Value.(*IntSlice)).Value(), error(nil) - if err != nil { - return nil - } - return parsed - } - return nil -} diff --git a/vendor/github.com/urfave/cli/flag_string_slice.go b/vendor/github.com/urfave/cli/flag_string_slice.go deleted file mode 100644 index e865b2ff03..0000000000 --- a/vendor/github.com/urfave/cli/flag_string_slice.go +++ /dev/null @@ -1,138 +0,0 @@ -package cli - -import ( - "flag" - "fmt" - "strings" -) - -// StringSlice is an opaque type for []string to satisfy flag.Value and flag.Getter -type StringSlice []string - -// Set appends the string value to the list of values -func (f *StringSlice) Set(value string) error { - *f = append(*f, value) - return nil -} - -// String returns a readable representation of this value (for usage defaults) -func (f *StringSlice) String() string { - return fmt.Sprintf("%s", *f) -} - -// Value returns the slice of strings set by this flag -func (f *StringSlice) Value() []string { - return *f -} - -// Get returns the slice of strings set by this flag -func (f *StringSlice) Get() interface{} { - return *f -} - -// StringSliceFlag is a flag with type *StringSlice -type StringSliceFlag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - TakesFile bool - Value *StringSlice -} - -// String returns a readable representation of this value -// (for usage defaults) -func (f StringSliceFlag) String() string { - return FlagStringer(f) -} - -// GetName returns the name of the flag -func (f StringSliceFlag) GetName() string { - return f.Name -} - -// IsRequired returns whether or not the flag is required -func (f StringSliceFlag) IsRequired() bool { - return f.Required -} - -// TakesValue returns true of the flag takes a value, otherwise false -func (f StringSliceFlag) TakesValue() bool { - return true -} - -// GetUsage returns the usage string for the flag -func (f StringSliceFlag) GetUsage() string { - return f.Usage -} - -// GetValue returns the flags value as string representation and an empty -// string if the flag takes no value at all. -func (f StringSliceFlag) GetValue() string { - if f.Value != nil { - return f.Value.String() - } - return "" -} - -// Apply populates the flag given the flag set and environment -// Ignores errors -func (f StringSliceFlag) Apply(set *flag.FlagSet) { - _ = f.ApplyWithError(set) -} - -// ApplyWithError populates the flag given the flag set and environment -func (f StringSliceFlag) ApplyWithError(set *flag.FlagSet) error { - if envVal, ok := flagFromFileEnv(f.FilePath, f.EnvVar); ok { - newVal := &StringSlice{} - for _, s := range strings.Split(envVal, ",") { - s = strings.TrimSpace(s) - if err := newVal.Set(s); err != nil { - return fmt.Errorf("could not parse %s as string value for flag %s: %s", envVal, f.Name, err) - } - } - if f.Value == nil { - f.Value = newVal - } else { - *f.Value = *newVal - } - } - - eachName(f.Name, func(name string) { - if f.Value == nil { - f.Value = &StringSlice{} - } - set.Var(f.Value, name, f.Usage) - }) - - return nil -} - -// StringSlice looks up the value of a local StringSliceFlag, returns -// nil if not found -func (c *Context) StringSlice(name string) []string { - return lookupStringSlice(name, c.flagSet) -} - -// GlobalStringSlice looks up the value of a global StringSliceFlag, returns -// nil if not found -func (c *Context) GlobalStringSlice(name string) []string { - if fs := lookupGlobalFlagSet(name, c); fs != nil { - return lookupStringSlice(name, fs) - } - return nil -} - -func lookupStringSlice(name string, set *flag.FlagSet) []string { - f := set.Lookup(name) - if f != nil { - parsed, err := (f.Value.(*StringSlice)).Value(), error(nil) - if err != nil { - return nil - } - return parsed - } - return nil -} diff --git a/vendor/github.com/urfave/cli/.flake8 b/vendor/github.com/urfave/cli/v2/.flake8 similarity index 100% rename from vendor/github.com/urfave/cli/.flake8 rename to vendor/github.com/urfave/cli/v2/.flake8 diff --git a/vendor/github.com/urfave/cli/.gitignore b/vendor/github.com/urfave/cli/v2/.gitignore similarity index 100% rename from vendor/github.com/urfave/cli/.gitignore rename to vendor/github.com/urfave/cli/v2/.gitignore diff --git a/vendor/github.com/urfave/cli/.travis.yml b/vendor/github.com/urfave/cli/v2/.travis.yml similarity index 79% rename from vendor/github.com/urfave/cli/.travis.yml rename to vendor/github.com/urfave/cli/v2/.travis.yml index d36c22436f..9f61c62f64 100644 --- a/vendor/github.com/urfave/cli/.travis.yml +++ b/vendor/github.com/urfave/cli/v2/.travis.yml @@ -12,8 +12,7 @@ os: - osx env: - GO111MODULE=on - GOPROXY=https://proxy.golang.org + GO111MODULE=on GOPROXY=https://proxy.golang.org cache: directories: @@ -30,6 +29,8 @@ script: - go run build.go test - go run build.go gfmrun docs/v1/manual.md - go run build.go toc docs/v1/manual.md + - go run build.go gfmrun docs/v2/manual.md + - go run build.go toc docs/v2/manual.md after_success: - bash <(curl -s https://codecov.io/bash) diff --git a/vendor/github.com/urfave/cli/CODE_OF_CONDUCT.md b/vendor/github.com/urfave/cli/v2/CODE_OF_CONDUCT.md similarity index 100% rename from vendor/github.com/urfave/cli/CODE_OF_CONDUCT.md rename to vendor/github.com/urfave/cli/v2/CODE_OF_CONDUCT.md diff --git a/vendor/github.com/urfave/cli/LICENSE b/vendor/github.com/urfave/cli/v2/LICENSE similarity index 100% rename from vendor/github.com/urfave/cli/LICENSE rename to vendor/github.com/urfave/cli/v2/LICENSE diff --git a/vendor/github.com/urfave/cli/README.md b/vendor/github.com/urfave/cli/v2/README.md similarity index 84% rename from vendor/github.com/urfave/cli/README.md rename to vendor/github.com/urfave/cli/v2/README.md index b2abbcf9db..ffb9e2e6e6 100644 --- a/vendor/github.com/urfave/cli/README.md +++ b/vendor/github.com/urfave/cli/v2/README.md @@ -15,29 +15,26 @@ applications in an expressive way. ## Usage Documentation -Usage documentation exists for each major version +Usage documentation exists for each major version. Don't know what version you're on? You're probably using the version from the `master` branch, which is currently `v2`. +- `v2` - [./docs/v2/manual.md](./docs/v2/manual.md) - `v1` - [./docs/v1/manual.md](./docs/v1/manual.md) -- `v2` - 🚧 documentation for `v2` is WIP 🚧 -## Installation - -Make sure you have a working Go environment. Go version 1.10+ is supported. [See -the install instructions for Go](http://golang.org/doc/install.html). +### Using `v2` releases -### GOPATH +**Warning**: `v2` is in a beta state. -Make sure your `PATH` includes the `$GOPATH/bin` directory so your commands can -be easily used: ``` -export PATH=$PATH:$GOPATH/bin +$ go get github.com/urfave/cli.v2 ``` -### Supported platforms - -cli is tested against multiple versions of Go on Linux, and against the latest -released version of Go on OS X and Windows. For full details, see -[`./.travis.yml`](./.travis.yml) and [`./appveyor.yml`](./appveyor.yml). +```go +... +import ( + "github.com/urfave/cli/v2" // imports as package "cli" +) +... +``` ### Using `v1` releases @@ -53,18 +50,21 @@ import ( ... ``` -### Using `v2` releases +## Installation + +Make sure you have a working Go environment. Go version 1.10+ is supported. [See +the install instructions for Go](http://golang.org/doc/install.html). -**Warning**: `v2` is in a pre-release state. +### GOPATH +Make sure your `PATH` includes the `$GOPATH/bin` directory so your commands can +be easily used: ``` -$ go get github.com/urfave/cli.v2 +export PATH=$PATH:$GOPATH/bin ``` -```go -... -import ( - "github.com/urfave/cli.v2" // imports as package "cli" -) -... -``` +### Supported platforms + +cli is tested against multiple versions of Go on Linux, and against the latest +released version of Go on OS X and Windows. For full details, see +[`./.travis.yml`](./.travis.yml) and [`./appveyor.yml`](./appveyor.yml). diff --git a/vendor/github.com/urfave/cli/app.go b/vendor/github.com/urfave/cli/v2/app.go similarity index 83% rename from vendor/github.com/urfave/cli/app.go rename to vendor/github.com/urfave/cli/v2/app.go index 95d2038101..d03ec5d71d 100644 --- a/vendor/github.com/urfave/cli/app.go +++ b/vendor/github.com/urfave/cli/v2/app.go @@ -6,6 +6,7 @@ import ( "io" "os" "path/filepath" + "reflect" "sort" "time" ) @@ -13,12 +14,8 @@ import ( var ( changeLogURL = "https://github.com/urfave/cli/blob/master/CHANGELOG.md" appActionDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-action-signature", changeLogURL) - // unused variable. commented for now. will remove in future if agreed upon by everyone - //runAndExitOnErrorDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-runandexitonerror", changeLogURL) - - contactSysadmin = "This is an error in the application. Please contact the distributor of this application if this is not you." - - errInvalidActionType = NewExitError("ERROR invalid Action type. "+ + contactSysadmin = "This is an error in the application. Please contact the distributor of this application if this is not you." + errInvalidActionType = NewExitError("ERROR invalid Action type. "+ fmt.Sprintf("Must be `func(*Context`)` or `func(*Context) error). %s", contactSysadmin)+ fmt.Sprintf("See %s", appActionDeprecationURL), 2) ) @@ -41,7 +38,7 @@ type App struct { // Description of the program Description string // List of commands to execute - Commands []Command + Commands []*Command // List of flags to parse Flags []Flag // Boolean to enable bash completion commands @@ -50,9 +47,9 @@ type App struct { HideHelp bool // Boolean to hide built-in version flag and the VERSION section of help HideVersion bool - // Populate on app startup, only gettable through method Categories() + // categories contains the categorized commands and is populated on app startup categories CommandCategories - // An action to execute when the bash-completion flag is set + // An action to execute when the shell completion flag is set BashComplete BashCompleteFunc // An action to execute before any subcommands are run, but after the context is ready // If a non-nil error is returned, no subcommands are run @@ -60,12 +57,8 @@ type App struct { // An action to execute after any subcommands are run, but after the subcommand has finished // It is run even if Action() panics After AfterFunc - // The action to execute when no subcommands are specified - // Expects a `cli.ActionFunc` but will accept the *deprecated* signature of `func(*cli.Context) {}` - // *Note*: support for the deprecated `Action` signature will be removed in a future version - Action interface{} - + Action ActionFunc // Execute this function if the proper command cannot be found CommandNotFound CommandNotFoundFunc // Execute this function if an usage error occurs @@ -73,13 +66,9 @@ type App struct { // Compilation date Compiled time.Time // List of all authors who contributed - Authors []Author + Authors []*Author // Copyright of the binary if any Copyright string - // Name of Author (Note: Use App.Authors, this is deprecated) - Author string - // Email of Author (Note: Use App.Authors, this is deprecated) - Email string // Writer writer to write output to Writer io.Writer // ErrWriter writes error output @@ -96,7 +85,7 @@ type App struct { // render custom help text by setting this variable. CustomAppHelpTemplate string // Boolean to enable short-option handling so user can combine several - // single-character bool arguements into one + // single-character bool arguments into one // i.e. foobar -o -v -> foobar -ov UseShortOptionHandling bool @@ -139,22 +128,52 @@ func (a *App) Setup() { a.didSetup = true - if a.Author != "" || a.Email != "" { - a.Authors = append(a.Authors, Author{Name: a.Author, Email: a.Email}) + if a.Name == "" { + a.Name = filepath.Base(os.Args[0]) + } + + if a.HelpName == "" { + a.HelpName = filepath.Base(os.Args[0]) + } + + if a.Usage == "" { + a.Usage = "A new cli application" + } + + if a.Version == "" { + a.Version = "0.0.0" + } + + if a.BashComplete == nil { + a.BashComplete = DefaultAppComplete + } + + if a.Action == nil { + a.Action = helpCommand.Action + } + + if a.Compiled == (time.Time{}) { + a.Compiled = compileTime() } - var newCmds []Command + if a.Writer == nil { + a.Writer = os.Stdout + } + + var newCommands []*Command + for _, c := range a.Commands { if c.HelpName == "" { c.HelpName = fmt.Sprintf("%s %s", a.HelpName, c.Name) } - newCmds = append(newCmds, c) + newCommands = append(newCommands, c) } - a.Commands = newCmds + a.Commands = newCommands if a.Command(helpCommand.Name) == nil && !a.HideHelp { - a.Commands = append(a.Commands, helpCommand) - if (HelpFlag != BoolFlag{}) { + a.appendCommand(helpCommand) + + if HelpFlag != nil { a.appendFlag(HelpFlag) } } @@ -163,11 +182,11 @@ func (a *App) Setup() { a.appendFlag(VersionFlag) } - a.categories = CommandCategories{} + a.categories = newCommandCategories() for _, command := range a.Commands { - a.categories = a.categories.AddCommand(command.Category, command) + a.categories.AddCommand(command.Category, command) } - sort.Sort(a.categories) + sort.Sort(a.categories.(*commandCategories)) if a.Metadata == nil { a.Metadata = make(map[string]interface{}) @@ -249,7 +268,7 @@ func (a *App) Run(arguments []string) (err error) { defer func() { if afterErr := a.After(context); afterErr != nil { if err != nil { - err = NewMultiError(err, afterErr) + err = newMultiError(err, afterErr) } else { err = afterErr } @@ -282,7 +301,7 @@ func (a *App) Run(arguments []string) (err error) { } // Run default Action - err = HandleAction(a.Action, context) + err = a.Action(context) a.handleExitCoder(context, err) return err @@ -303,17 +322,20 @@ func (a *App) RunAndExitOnError() { // RunAsSubcommand invokes the subcommand given the context, parses ctx.Args() to // generate command-specific flags func (a *App) RunAsSubcommand(ctx *Context) (err error) { + a.Setup() + // append help to commands if len(a.Commands) > 0 { if a.Command(helpCommand.Name) == nil && !a.HideHelp { - a.Commands = append(a.Commands, helpCommand) - if (HelpFlag != BoolFlag{}) { + a.appendCommand(helpCommand) + + if HelpFlag != nil { a.appendFlag(HelpFlag) } } } - newCmds := []Command{} + var newCmds []*Command for _, c := range a.Commands { if c.HelpName == "" { c.HelpName = fmt.Sprintf("%s %s", a.HelpName, c.Name) @@ -379,7 +401,7 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) { if afterErr != nil { a.handleExitCoder(context, err) if err != nil { - err = NewMultiError(err, afterErr) + err = newMultiError(err, afterErr) } else { err = afterErr } @@ -406,7 +428,7 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) { } // Run default Action - err = HandleAction(a.Action, context) + err = a.Action(context) a.handleExitCoder(context, err) return err @@ -416,28 +438,21 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) { func (a *App) Command(name string) *Command { for _, c := range a.Commands { if c.HasName(name) { - return &c + return c } } return nil } -// Categories returns a slice containing all the categories with the commands they contain -func (a *App) Categories() CommandCategories { - return a.categories -} - // VisibleCategories returns a slice of categories and commands that are // Hidden=false -func (a *App) VisibleCategories() []*CommandCategory { - ret := []*CommandCategory{} - for _, category := range a.categories { - if visible := func() *CommandCategory { - for _, command := range category.Commands { - if !command.Hidden { - return category - } +func (a *App) VisibleCategories() []CommandCategory { + ret := []CommandCategory{} + for _, category := range a.categories.Categories() { + if visible := func() CommandCategory { + if len(category.VisibleCommands()) > 0 { + return category } return nil }(); visible != nil { @@ -448,8 +463,8 @@ func (a *App) VisibleCategories() []*CommandCategory { } // VisibleCommands returns a slice of the Commands with Hidden=false -func (a *App) VisibleCommands() []Command { - var ret []Command +func (a *App) VisibleCommands() []*Command { + var ret []*Command for _, command := range a.Commands { if !command.Hidden { ret = append(ret, command) @@ -465,7 +480,7 @@ func (a *App) VisibleFlags() []Flag { func (a *App) hasFlag(flag Flag) bool { for _, f := range a.Flags { - if flag == f { + if reflect.DeepEqual(flag, f) { return true } } @@ -482,9 +497,15 @@ func (a *App) errWriter() io.Writer { return a.ErrWriter } -func (a *App) appendFlag(flag Flag) { - if !a.hasFlag(flag) { - a.Flags = append(a.Flags, flag) +func (a *App) appendFlag(fl Flag) { + if !hasFlag(a.Flags, fl) { + a.Flags = append(a.Flags, fl) + } +} + +func (a *App) appendCommand(c *Command) { + if !hasCommand(a.Commands, c) { + a.Commands = append(a.Commands, c) } } @@ -503,7 +524,7 @@ type Author struct { } // String makes Author comply to the Stringer interface, to allow an easy print in the templating process -func (a Author) String() string { +func (a *Author) String() string { e := "" if a.Email != "" { e = " <" + a.Email + ">" diff --git a/vendor/github.com/urfave/cli/appveyor.yml b/vendor/github.com/urfave/cli/v2/appveyor.yml similarity index 89% rename from vendor/github.com/urfave/cli/appveyor.yml rename to vendor/github.com/urfave/cli/v2/appveyor.yml index 8ef2fea1a6..d8f589b0ec 100644 --- a/vendor/github.com/urfave/cli/appveyor.yml +++ b/vendor/github.com/urfave/cli/v2/appveyor.yml @@ -20,7 +20,8 @@ install: - go version - go env - go get github.com/urfave/gfmrun/cmd/gfmrun - - go mod vendor + - go get golang.org/x/tools/cmd/goimports + - go mod tidy build_script: - go run build.go vet diff --git a/vendor/github.com/urfave/cli/v2/args.go b/vendor/github.com/urfave/cli/v2/args.go new file mode 100644 index 0000000000..bd65c17bde --- /dev/null +++ b/vendor/github.com/urfave/cli/v2/args.go @@ -0,0 +1,54 @@ +package cli + +type Args interface { + // Get returns the nth argument, or else a blank string + Get(n int) string + // First returns the first argument, or else a blank string + First() string + // Tail returns the rest of the arguments (not the first one) + // or else an empty string slice + Tail() []string + // Len returns the length of the wrapped slice + Len() int + // Present checks if there are any arguments present + Present() bool + // Slice returns a copy of the internal slice + Slice() []string +} + +type args []string + +func (a *args) Get(n int) string { + if len(*a) > n { + return (*a)[n] + } + return "" +} + +func (a *args) First() string { + return a.Get(0) +} + +func (a *args) Tail() []string { + if a.Len() >= 2 { + tail := []string((*a)[1:]) + ret := make([]string, len(tail)) + copy(ret, tail) + return ret + } + return []string{} +} + +func (a *args) Len() int { + return len(*a) +} + +func (a *args) Present() bool { + return a.Len() != 0 +} + +func (a *args) Slice() []string { + ret := make([]string, len(*a)) + copy(ret, *a) + return ret +} diff --git a/vendor/github.com/urfave/cli/v2/category.go b/vendor/github.com/urfave/cli/v2/category.go new file mode 100644 index 0000000000..d9e73a0bf0 --- /dev/null +++ b/vendor/github.com/urfave/cli/v2/category.go @@ -0,0 +1,78 @@ +package cli + +type CommandCategories interface { + // AddCommand adds a command to a category, creating a new category if necessary. + AddCommand(category string, command *Command) + // categories returns a copy of the category slice + Categories() []CommandCategory +} + +type commandCategories []*commandCategory + +func newCommandCategories() CommandCategories { + ret := commandCategories([]*commandCategory{}) + return &ret +} + +func (c *commandCategories) Less(i, j int) bool { + return lexicographicLess((*c)[i].Name(), (*c)[j].Name()) +} + +func (c *commandCategories) Len() int { + return len(*c) +} + +func (c *commandCategories) Swap(i, j int) { + (*c)[i], (*c)[j] = (*c)[j], (*c)[i] +} + +func (c *commandCategories) AddCommand(category string, command *Command) { + for _, commandCategory := range []*commandCategory(*c) { + if commandCategory.name == category { + commandCategory.commands = append(commandCategory.commands, command) + return + } + } + newVal := append(*c, + &commandCategory{name: category, commands: []*Command{command}}) + *c = newVal +} + +func (c *commandCategories) Categories() []CommandCategory { + ret := make([]CommandCategory, len(*c)) + for i, cat := range *c { + ret[i] = cat + } + return ret +} + +// CommandCategory is a category containing commands. +type CommandCategory interface { + // Name returns the category name string + Name() string + // VisibleCommands returns a slice of the Commands with Hidden=false + VisibleCommands() []*Command +} + +type commandCategory struct { + name string + commands []*Command +} + +func (c *commandCategory) Name() string { + return c.name +} + +func (c *commandCategory) VisibleCommands() []*Command { + if c.commands == nil { + c.commands = []*Command{} + } + + var ret []*Command + for _, command := range c.commands { + if !command.Hidden { + ret = append(ret, command) + } + } + return ret +} diff --git a/vendor/github.com/urfave/cli/cli.go b/vendor/github.com/urfave/cli/v2/cli.go similarity index 67% rename from vendor/github.com/urfave/cli/cli.go rename to vendor/github.com/urfave/cli/v2/cli.go index 4bd2508392..62a5bc22d2 100644 --- a/vendor/github.com/urfave/cli/cli.go +++ b/vendor/github.com/urfave/cli/v2/cli.go @@ -2,18 +2,19 @@ // Go applications. cli is designed to be easy to understand and write, the most simple // cli application can be written as follows: // func main() { -// cli.NewApp().Run(os.Args) +// (&cli.App{}).Run(os.Args) // } // // Of course this application does not do much, so let's make this an actual application: // func main() { -// app := cli.NewApp() -// app.Name = "greet" -// app.Usage = "say a greeting" -// app.Action = func(c *cli.Context) error { -// println("Greetings") -// return nil -// } +// app := &cli.App{ +// Name: "greet", +// Usage: "say a greeting", +// Action: func(c *cli.Context) error { +// fmt.Println("Greetings") +// return nil +// }, +// } // // app.Run(os.Args) // } diff --git a/vendor/github.com/urfave/cli/command.go b/vendor/github.com/urfave/cli/v2/command.go similarity index 57% rename from vendor/github.com/urfave/cli/command.go rename to vendor/github.com/urfave/cli/v2/command.go index e7cb97a6af..a579fdb06a 100644 --- a/vendor/github.com/urfave/cli/command.go +++ b/vendor/github.com/urfave/cli/v2/command.go @@ -11,8 +11,6 @@ import ( type Command struct { // The name of the command Name string - // short name of the command. Typically one character (deprecated, use `Aliases`) - ShortName string // A list of aliases for the command Aliases []string // A short description of the usage of this command @@ -34,23 +32,15 @@ type Command struct { // It is run even if Action() panics After AfterFunc // The function to call when this command is invoked - Action interface{} - // TODO: replace `Action: interface{}` with `Action: ActionFunc` once some kind - // of deprecation period has passed, maybe? - + Action ActionFunc // Execute this function if a usage error occurs. OnUsageError OnUsageErrorFunc // List of child commands - Subcommands Commands + Subcommands []*Command // List of flags to parse Flags []Flag // Treat all flags as normal arguments if true SkipFlagParsing bool - // Skip argument reordering which attempts to move flags before arguments, - // but only works if all flags appear after all arguments. This behavior was - // removed n version 2 since it only works under specific conditions so we - // backport here by exposing it as an option for compatibility. - SkipArgReorder bool // Boolean to hide built-in help command HideHelp bool // Boolean to hide this command from help or completion @@ -70,7 +60,9 @@ type Command struct { CustomHelpTemplate string } -type CommandsByName []Command +type Commands []*Command + +type CommandsByName []*Command func (c CommandsByName) Len() int { return len(c) @@ -86,35 +78,29 @@ func (c CommandsByName) Swap(i, j int) { // FullName returns the full name of the command. // For subcommands this ensures that parent commands are part of the command path -func (c Command) FullName() string { +func (c *Command) FullName() string { if c.commandNamePath == nil { return c.Name } return strings.Join(c.commandNamePath, " ") } -// Commands is a slice of Command -type Commands []Command - // Run invokes the command given the context, parses ctx.Args() to generate command-specific flags -func (c Command) Run(ctx *Context) (err error) { +func (c *Command) Run(ctx *Context) (err error) { if len(c.Subcommands) > 0 { return c.startApp(ctx) } - if !c.HideHelp && (HelpFlag != BoolFlag{}) { + if !c.HideHelp && HelpFlag != nil { // append help to flags - c.Flags = append( - c.Flags, - HelpFlag, - ) + c.appendFlag(HelpFlag) } if ctx.App.UseShortOptionHandling { c.UseShortOptionHandling = true } - set, err := c.parseFlags(ctx.Args().Tail()) + set, err := c.parseFlags(ctx.Args()) context := NewContext(ctx.App, set, ctx) context.Command = c @@ -124,7 +110,7 @@ func (c Command) Run(ctx *Context) (err error) { if err != nil { if c.OnUsageError != nil { - err := c.OnUsageError(context, err, false) + err = c.OnUsageError(context, err, false) context.App.handleExitCoder(context, err) return err } @@ -150,7 +136,7 @@ func (c Command) Run(ctx *Context) (err error) { if afterErr != nil { context.App.handleExitCoder(context, err) if err != nil { - err = NewMultiError(err, afterErr) + err = newMultiError(err, afterErr) } else { err = afterErr } @@ -171,7 +157,8 @@ func (c Command) Run(ctx *Context) (err error) { c.Action = helpSubcommand.Action } - err = HandleAction(c.Action, context) + context.Command = c + err = c.Action(context) if err != nil { context.App.handleExitCoder(context, err) @@ -179,26 +166,25 @@ func (c Command) Run(ctx *Context) (err error) { return err } -func (c *Command) parseFlags(args Args) (*flag.FlagSet, error) { - if c.SkipFlagParsing { - set, err := c.newFlagSet() - if err != nil { - return nil, err - } - - return set, set.Parse(append([]string{"--"}, args...)) - } +func (c *Command) newFlagSet() (*flag.FlagSet, error) { + return flagSet(c.Name, c.Flags) +} - if !c.SkipArgReorder { - args = reorderArgs(c.Flags, args) - } +func (c *Command) useShortOptionHandling() bool { + return c.UseShortOptionHandling +} +func (c *Command) parseFlags(args Args) (*flag.FlagSet, error) { set, err := c.newFlagSet() if err != nil { return nil, err } - err = parseIter(set, c, args) + if c.SkipFlagParsing { + return set, set.Parse(append([]string{"--"}, args.Tail()...)) + } + + err = parseIter(set, c, args.Tail()) if err != nil { return nil, err } @@ -211,96 +197,13 @@ func (c *Command) parseFlags(args Args) (*flag.FlagSet, error) { return set, nil } -func (c *Command) newFlagSet() (*flag.FlagSet, error) { - return flagSet(c.Name, c.Flags) -} - -func (c *Command) useShortOptionHandling() bool { - return c.UseShortOptionHandling -} - -// reorderArgs moves all flags (via reorderedArgs) before the rest of -// the arguments (remainingArgs) as this is what flag expects. -func reorderArgs(commandFlags []Flag, args []string) []string { - var remainingArgs, reorderedArgs []string - - nextIndexMayContainValue := false - for i, arg := range args { - - // dont reorder any args after a -- - // read about -- here: - // https://unix.stackexchange.com/questions/11376/what-does-double-dash-mean-also-known-as-bare-double-dash - if arg == "--" { - remainingArgs = append(remainingArgs, args[i:]...) - break - - // checks if this arg is a value that should be re-ordered next to its associated flag - } else if nextIndexMayContainValue && !strings.HasPrefix(arg, "-") { - nextIndexMayContainValue = false - reorderedArgs = append(reorderedArgs, arg) - - // checks if this is an arg that should be re-ordered - } else if argIsFlag(commandFlags, arg) { - // we have determined that this is a flag that we should re-order - reorderedArgs = append(reorderedArgs, arg) - // if this arg does not contain a "=", then the next index may contain the value for this flag - nextIndexMayContainValue = !strings.Contains(arg, "=") - - // simply append any remaining args - } else { - remainingArgs = append(remainingArgs, arg) - } - } - - return append(reorderedArgs, remainingArgs...) -} - -// argIsFlag checks if an arg is one of our command flags -func argIsFlag(commandFlags []Flag, arg string) bool { - // checks if this is just a `-`, and so definitely not a flag - if arg == "-" { - return false - } - // flags always start with a - - if !strings.HasPrefix(arg, "-") { - return false - } - // this line turns `--flag` into `flag` - if strings.HasPrefix(arg, "--") { - arg = strings.Replace(arg, "-", "", 2) - } - // this line turns `-flag` into `flag` - if strings.HasPrefix(arg, "-") { - arg = strings.Replace(arg, "-", "", 1) - } - // this line turns `flag=value` into `flag` - arg = strings.Split(arg, "=")[0] - // look through all the flags, to see if the `arg` is one of our flags - for _, flag := range commandFlags { - for _, key := range strings.Split(flag.GetName(), ",") { - key := strings.TrimSpace(key) - if key == arg { - return true - } - } - } - // return false if this arg was not one of our flags - return false -} - // Names returns the names including short names and aliases. -func (c Command) Names() []string { - names := []string{c.Name} - - if c.ShortName != "" { - names = append(names, c.ShortName) - } - - return append(names, c.Aliases...) +func (c *Command) Names() []string { + return append([]string{c.Name}, c.Aliases...) } -// HasName returns true if Command.Name or Command.ShortName matches given name -func (c Command) HasName(name string) bool { +// HasName returns true if Command.Name matches given name +func (c *Command) HasName(name string) bool { for _, n := range c.Names() { if n == name { return true @@ -309,12 +212,12 @@ func (c Command) HasName(name string) bool { return false } -func (c Command) startApp(ctx *Context) error { - app := NewApp() - app.Metadata = ctx.App.Metadata - app.ExitErrHandler = ctx.App.ExitErrHandler - // set the name and usage - app.Name = fmt.Sprintf("%s %s", ctx.App.Name, c.Name) +func (c *Command) startApp(ctx *Context) error { + app := &App{ + Metadata: ctx.App.Metadata, + Name: fmt.Sprintf("%s %s", ctx.App.Name, c.Name), + } + if c.HelpName == "" { app.HelpName = c.HelpName } else { @@ -337,18 +240,17 @@ func (c Command) startApp(ctx *Context) error { app.Version = ctx.App.Version app.HideVersion = ctx.App.HideVersion app.Compiled = ctx.App.Compiled - app.Author = ctx.App.Author - app.Email = ctx.App.Email app.Writer = ctx.App.Writer app.ErrWriter = ctx.App.ErrWriter + app.ExitErrHandler = ctx.App.ExitErrHandler app.UseShortOptionHandling = ctx.App.UseShortOptionHandling - app.categories = CommandCategories{} + app.categories = newCommandCategories() for _, command := range c.Subcommands { - app.categories = app.categories.AddCommand(command.Category, command) + app.categories.AddCommand(command.Category, command) } - sort.Sort(app.categories) + sort.Sort(app.categories.(*commandCategories)) // bash completion app.EnableBashCompletion = ctx.App.EnableBashCompletion @@ -374,6 +276,22 @@ func (c Command) startApp(ctx *Context) error { } // VisibleFlags returns a slice of the Flags with Hidden=false -func (c Command) VisibleFlags() []Flag { +func (c *Command) VisibleFlags() []Flag { return visibleFlags(c.Flags) } + +func (c *Command) appendFlag(fl Flag) { + if !hasFlag(c.Flags, fl) { + c.Flags = append(c.Flags, fl) + } +} + +func hasCommand(commands []*Command, command *Command) bool { + for _, existing := range commands { + if command == existing { + return true + } + } + + return false +} diff --git a/vendor/github.com/urfave/cli/v2/context.go b/vendor/github.com/urfave/cli/v2/context.go new file mode 100644 index 0000000000..535c38818a --- /dev/null +++ b/vendor/github.com/urfave/cli/v2/context.go @@ -0,0 +1,281 @@ +package cli + +import ( + "context" + "errors" + "flag" + "fmt" + "os" + "os/signal" + "strings" + "syscall" +) + +// Context is a type that is passed through to +// each Handler action in a cli application. Context +// can be used to retrieve context-specific args and +// parsed command-line options. +type Context struct { + context.Context + App *App + Command *Command + shellComplete bool + setFlags map[string]bool + flagSet *flag.FlagSet + parentContext *Context +} + +// NewContext creates a new context. For use in when invoking an App or Command action. +func NewContext(app *App, set *flag.FlagSet, parentCtx *Context) *Context { + c := &Context{App: app, flagSet: set, parentContext: parentCtx} + if parentCtx != nil { + c.Context = parentCtx.Context + c.shellComplete = parentCtx.shellComplete + } + + c.Command = &Command{} + + if c.Context == nil { + ctx, cancel := context.WithCancel(context.Background()) + go func() { + defer cancel() + sigs := make(chan os.Signal, 1) + signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) + <-sigs + }() + c.Context = ctx + } + + return c +} + +// NumFlags returns the number of flags set +func (c *Context) NumFlags() int { + return c.flagSet.NFlag() +} + +// Set sets a context flag to a value. +func (c *Context) Set(name, value string) error { + return c.flagSet.Set(name, value) +} + +// IsSet determines if the flag was actually set +func (c *Context) IsSet(name string) bool { + if fs := lookupFlagSet(name, c); fs != nil { + if fs := lookupFlagSet(name, c); fs != nil { + isSet := false + fs.Visit(func(f *flag.Flag) { + if f.Name == name { + isSet = true + } + }) + if isSet { + return true + } + } + + f := lookupFlag(name, c) + if f == nil { + return false + } + + return f.IsSet() + } + + return false +} + +// LocalFlagNames returns a slice of flag names used in this context. +func (c *Context) LocalFlagNames() []string { + var names []string + c.flagSet.Visit(makeFlagNameVisitor(&names)) + return names +} + +// FlagNames returns a slice of flag names used by the this context and all of +// its parent contexts. +func (c *Context) FlagNames() []string { + var names []string + for _, ctx := range c.Lineage() { + ctx.flagSet.Visit(makeFlagNameVisitor(&names)) + } + return names +} + +// Lineage returns *this* context and all of its ancestor contexts in order from +// child to parent +func (c *Context) Lineage() []*Context { + var lineage []*Context + + for cur := c; cur != nil; cur = cur.parentContext { + lineage = append(lineage, cur) + } + + return lineage +} + +// value returns the value of the flag corresponding to `name` +func (c *Context) value(name string) interface{} { + return c.flagSet.Lookup(name).Value.(flag.Getter).Get() +} + +// Args returns the command line arguments associated with the context. +func (c *Context) Args() Args { + ret := args(c.flagSet.Args()) + return &ret +} + +// NArg returns the number of the command line arguments. +func (c *Context) NArg() int { + return c.Args().Len() +} + +func lookupFlag(name string, ctx *Context) Flag { + for _, c := range ctx.Lineage() { + if c.Command == nil { + continue + } + + for _, f := range c.Command.Flags { + for _, n := range f.Names() { + if n == name { + return f + } + } + } + } + + if ctx.App != nil { + for _, f := range ctx.App.Flags { + for _, n := range f.Names() { + if n == name { + return f + } + } + } + } + + return nil +} + +func lookupFlagSet(name string, ctx *Context) *flag.FlagSet { + for _, c := range ctx.Lineage() { + if f := c.flagSet.Lookup(name); f != nil { + return c.flagSet + } + } + + return nil +} + +func copyFlag(name string, ff *flag.Flag, set *flag.FlagSet) { + switch ff.Value.(type) { + case Serializer: + _ = set.Set(name, ff.Value.(Serializer).Serialize()) + default: + _ = set.Set(name, ff.Value.String()) + } +} + +func normalizeFlags(flags []Flag, set *flag.FlagSet) error { + visited := make(map[string]bool) + set.Visit(func(f *flag.Flag) { + visited[f.Name] = true + }) + for _, f := range flags { + parts := f.Names() + if len(parts) == 1 { + continue + } + var ff *flag.Flag + for _, name := range parts { + name = strings.Trim(name, " ") + if visited[name] { + if ff != nil { + return errors.New("Cannot use two forms of the same flag: " + name + " " + ff.Name) + } + ff = set.Lookup(name) + } + } + if ff == nil { + continue + } + for _, name := range parts { + name = strings.Trim(name, " ") + if !visited[name] { + copyFlag(name, ff, set) + } + } + } + return nil +} + +func makeFlagNameVisitor(names *[]string) func(*flag.Flag) { + return func(f *flag.Flag) { + nameParts := strings.Split(f.Name, ",") + name := strings.TrimSpace(nameParts[0]) + + for _, part := range nameParts { + part = strings.TrimSpace(part) + if len(part) > len(name) { + name = part + } + } + + if name != "" { + *names = append(*names, name) + } + } +} + +type requiredFlagsErr interface { + error + getMissingFlags() []string +} + +type errRequiredFlags struct { + missingFlags []string +} + +func (e *errRequiredFlags) Error() string { + numberOfMissingFlags := len(e.missingFlags) + if numberOfMissingFlags == 1 { + return fmt.Sprintf("Required flag %q not set", e.missingFlags[0]) + } + joinedMissingFlags := strings.Join(e.missingFlags, ", ") + return fmt.Sprintf("Required flags %q not set", joinedMissingFlags) +} + +func (e *errRequiredFlags) getMissingFlags() []string { + return e.missingFlags +} + +func checkRequiredFlags(flags []Flag, context *Context) requiredFlagsErr { + var missingFlags []string + for _, f := range flags { + if rf, ok := f.(RequiredFlag); ok && rf.IsRequired() { + var flagPresent bool + var flagName string + + for _, key := range f.Names() { + if len(key) > 1 { + flagName = key + } + + if context.IsSet(strings.TrimSpace(key)) { + flagPresent = true + } + } + + if !flagPresent && flagName != "" { + missingFlags = append(missingFlags, flagName) + } + } + } + + if len(missingFlags) != 0 { + return &errRequiredFlags{missingFlags: missingFlags} + } + + return nil +} diff --git a/vendor/github.com/urfave/cli/docs.go b/vendor/github.com/urfave/cli/v2/docs.go similarity index 93% rename from vendor/github.com/urfave/cli/docs.go rename to vendor/github.com/urfave/cli/v2/docs.go index 5b94566128..a8f5de92e5 100644 --- a/vendor/github.com/urfave/cli/docs.go +++ b/vendor/github.com/urfave/cli/v2/docs.go @@ -53,10 +53,9 @@ func (a *App) writeDocTemplate(w io.Writer) error { }) } -func prepareCommands(commands []Command, level int) []string { - coms := []string{} - for i := range commands { - command := &commands[i] +func prepareCommands(commands []*Command, level int) []string { + var coms []string + for _, command := range commands { if command.Hidden { continue } @@ -110,7 +109,8 @@ func prepareFlags( continue } modifiedArg := opener - for _, s := range strings.Split(flag.GetName(), ",") { + + for _, s := range flag.Names() { trimmed := strings.TrimSpace(s) if len(modifiedArg) > len(opener) { modifiedArg += sep diff --git a/vendor/github.com/urfave/cli/errors.go b/vendor/github.com/urfave/cli/v2/errors.go similarity index 63% rename from vendor/github.com/urfave/cli/errors.go rename to vendor/github.com/urfave/cli/v2/errors.go index 562b2953cf..be589033aa 100644 --- a/vendor/github.com/urfave/cli/errors.go +++ b/vendor/github.com/urfave/cli/v2/errors.go @@ -15,25 +15,39 @@ var OsExiter = os.Exit var ErrWriter io.Writer = os.Stderr // MultiError is an error that wraps multiple errors. -type MultiError struct { - Errors []error +type MultiError interface { + error + // Errors returns a copy of the errors slice + Errors() []error } // NewMultiError creates a new MultiError. Pass in one or more errors. -func NewMultiError(err ...error) MultiError { - return MultiError{Errors: err} +func newMultiError(err ...error) MultiError { + ret := multiError(err) + return &ret } +type multiError []error + // Error implements the error interface. -func (m MultiError) Error() string { - errs := make([]string, len(m.Errors)) - for i, err := range m.Errors { +func (m *multiError) Error() string { + errs := make([]string, len(*m)) + for i, err := range *m { errs[i] = err.Error() } return strings.Join(errs, "\n") } +// Errors returns a copy of the errors slice +func (m *multiError) Errors() []error { + errs := make([]error, len(*m)) + for _, err := range *m { + errs = append(errs, err) + } + return errs +} + type ErrorFormatter interface { Format(s fmt.State, verb rune) } @@ -45,29 +59,30 @@ type ExitCoder interface { ExitCode() int } -// ExitError fulfills both the builtin `error` interface and `ExitCoder` -type ExitError struct { +type exitError struct { exitCode int message interface{} } -// NewExitError makes a new *ExitError -func NewExitError(message interface{}, exitCode int) *ExitError { - return &ExitError{ - exitCode: exitCode, +// NewExitError makes a new *exitError +func NewExitError(message interface{}, exitCode int) ExitCoder { + return Exit(message, exitCode) +} + +// Exit wraps a message and exit code into an ExitCoder suitable for handling by +// HandleExitCoder +func Exit(message interface{}, exitCode int) ExitCoder { + return &exitError{ message: message, + exitCode: exitCode, } } -// Error returns the string message, fulfilling the interface required by -// `error` -func (ee *ExitError) Error() string { +func (ee *exitError) Error() string { return fmt.Sprintf("%v", ee.message) } -// ExitCode returns the exit code, fulfilling the interface required by -// `ExitCoder` -func (ee *ExitError) ExitCode() int { +func (ee *exitError) ExitCode() int { return ee.exitCode } @@ -83,9 +98,9 @@ func HandleExitCoder(err error) { if exitErr, ok := err.(ExitCoder); ok { if err.Error() != "" { if _, ok := exitErr.(ErrorFormatter); ok { - fmt.Fprintf(ErrWriter, "%+v\n", err) + _, _ = fmt.Fprintf(ErrWriter, "%+v\n", err) } else { - fmt.Fprintln(ErrWriter, err) + _, _ = fmt.Fprintln(ErrWriter, err) } } OsExiter(exitErr.ExitCode()) @@ -101,10 +116,10 @@ func HandleExitCoder(err error) { func handleMultiError(multiErr MultiError) int { code := 1 - for _, merr := range multiErr.Errors { + for _, merr := range multiErr.Errors() { if multiErr2, ok := merr.(MultiError); ok { code = handleMultiError(multiErr2) - } else { + } else if merr != nil { fmt.Fprintln(ErrWriter, merr) if exitErr, ok := merr.(ExitCoder); ok { code = exitErr.ExitCode() diff --git a/vendor/github.com/urfave/cli/fish.go b/vendor/github.com/urfave/cli/v2/fish.go similarity index 93% rename from vendor/github.com/urfave/cli/fish.go rename to vendor/github.com/urfave/cli/v2/fish.go index cf183af611..67122c9fe7 100644 --- a/vendor/github.com/urfave/cli/fish.go +++ b/vendor/github.com/urfave/cli/v2/fish.go @@ -64,11 +64,9 @@ func (a *App) writeFishCompletionTemplate(w io.Writer) error { }) } -func (a *App) prepareFishCommands(commands []Command, allCommands *[]string, previousCommands []string) []string { +func (a *App) prepareFishCommands(commands []*Command, allCommands *[]string, previousCommands []string) []string { completions := []string{} - for i := range commands { - command := &commands[i] - + for _, command := range commands { if command.Hidden { continue } @@ -131,7 +129,7 @@ func (a *App) prepareFishFlags(flags []Flag, previousCommands []string) []string fishAddFileFlag(f, completion) - for idx, opt := range strings.Split(flag.GetName(), ",") { + for idx, opt := range flag.Names() { if idx == 0 { completion.WriteString(fmt.Sprintf( " -l %s", strings.TrimSpace(opt), @@ -161,15 +159,15 @@ func (a *App) prepareFishFlags(flags []Flag, previousCommands []string) []string func fishAddFileFlag(flag Flag, completion *strings.Builder) { switch f := flag.(type) { - case GenericFlag: + case *GenericFlag: if f.TakesFile { return } - case StringFlag: + case *StringFlag: if f.TakesFile { return } - case StringSliceFlag: + case *StringSliceFlag: if f.TakesFile { return } diff --git a/vendor/github.com/urfave/cli/flag.go b/vendor/github.com/urfave/cli/v2/flag.go similarity index 55% rename from vendor/github.com/urfave/cli/flag.go rename to vendor/github.com/urfave/cli/v2/flag.go index 1cfa1cdb21..ec128fd440 100644 --- a/vendor/github.com/urfave/cli/flag.go +++ b/vendor/github.com/urfave/cli/v2/flag.go @@ -5,38 +5,53 @@ import ( "fmt" "io/ioutil" "reflect" + "regexp" "runtime" "strconv" "strings" "syscall" + "time" ) const defaultPlaceholder = "value" +var ( + slPfx = fmt.Sprintf("sl:::%d:::", time.Now().UTC().UnixNano()) + + commaWhitespace = regexp.MustCompile("[, ]+.*") +) + // BashCompletionFlag enables bash-completion for all commands and subcommands -var BashCompletionFlag Flag = BoolFlag{ +var BashCompletionFlag Flag = &BoolFlag{ Name: "generate-bash-completion", Hidden: true, } // VersionFlag prints the version for the application -var VersionFlag Flag = BoolFlag{ - Name: "version, v", - Usage: "print the version", +var VersionFlag Flag = &BoolFlag{ + Name: "version", + Aliases: []string{"v"}, + Usage: "print the version", } -// HelpFlag prints the help for all commands and subcommands -// Set to the zero value (BoolFlag{}) to disable flag -- keeps subcommand -// unless HideHelp is set to true) -var HelpFlag Flag = BoolFlag{ - Name: "help, h", - Usage: "show help", +// HelpFlag prints the help for all commands and subcommands. +// Set to nil to disable the flag. The subcommand +// will still be added unless HideHelp is set to true. +var HelpFlag Flag = &BoolFlag{ + Name: "help", + Aliases: []string{"h"}, + Usage: "show help", } // FlagStringer converts a flag definition to a string. This is used by help // to display a flag. var FlagStringer FlagStringFunc = stringifyFlag +// Serializer is used to circumvent the limitations of flag.FlagSet.Set +type Serializer interface { + Serialize() string +} + // FlagNamePrefixer converts a full flag name and its placeholder into the help // message flag prefix. This is used by the default FlagStringer. var FlagNamePrefixer FlagNamePrefixFunc = prefixedNames @@ -57,7 +72,12 @@ func (f FlagsByName) Len() int { } func (f FlagsByName) Less(i, j int) bool { - return lexicographicLess(f[i].GetName(), f[j].GetName()) + if len(f[j].Names()) == 0 { + return false + } else if len(f[i].Names()) == 0 { + return true + } + return lexicographicLess(f[i].Names()[0], f[j].Names()[0]) } func (f FlagsByName) Swap(i, j int) { @@ -70,8 +90,9 @@ func (f FlagsByName) Swap(i, j int) { type Flag interface { fmt.Stringer // Apply Flag settings to the given flag set - Apply(*flag.FlagSet) - GetName() string + Apply(*flag.FlagSet) error + Names() []string + IsSet() bool } // RequiredFlag is an interface that allows us to mark flags as required @@ -97,40 +118,18 @@ type DocGenerationFlag interface { GetValue() string } -// errorableFlag is an interface that allows us to return errors during apply -// it allows flags defined in this library to return errors in a fashion backwards compatible -// TODO remove in v2 and modify the existing Flag interface to return errors -type errorableFlag interface { - Flag - - ApplyWithError(*flag.FlagSet) error -} - func flagSet(name string, flags []Flag) (*flag.FlagSet, error) { set := flag.NewFlagSet(name, flag.ContinueOnError) for _, f := range flags { - //TODO remove in v2 when errorableFlag is removed - if ef, ok := f.(errorableFlag); ok { - if err := ef.ApplyWithError(set); err != nil { - return nil, err - } - } else { - f.Apply(set) + if err := f.Apply(set); err != nil { + return nil, err } } set.SetOutput(ioutil.Discard) return set, nil } -func eachName(longName string, fn func(string)) { - parts := strings.Split(longName, ",") - for _, name := range parts { - name = strings.Trim(name, " ") - fn(name) - } -} - func visibleFlags(fl []Flag) []Flag { var visible []Flag for _, f := range fl { @@ -169,25 +168,27 @@ func unquoteUsage(usage string) (string, string) { return "", usage } -func prefixedNames(fullName, placeholder string) string { +func prefixedNames(names []string, placeholder string) string { var prefixed string - parts := strings.Split(fullName, ",") - for i, name := range parts { - name = strings.Trim(name, " ") + for i, name := range names { + if name == "" { + continue + } + prefixed += prefixFor(name) + name if placeholder != "" { prefixed += " " + placeholder } - if i < len(parts)-1 { + if i < len(names)-1 { prefixed += ", " } } return prefixed } -func withEnvHint(envVar, str string) string { +func withEnvHint(envVars []string, str string) string { envText := "" - if envVar != "" { + if envVars != nil && len(envVars) > 0 { prefix := "$" suffix := "" sep := ", $" @@ -196,11 +197,51 @@ func withEnvHint(envVar, str string) string { suffix = "%" sep = "%, %" } - envText = " [" + prefix + strings.Join(strings.Split(envVar, ","), sep) + suffix + "]" + + envText = fmt.Sprintf(" [%s%s%s]", prefix, strings.Join(envVars, sep), suffix) } return str + envText } +func flagNames(f Flag) []string { + var ret []string + + name := flagStringField(f, "Name") + aliases := flagStringSliceField(f, "Aliases") + + for _, part := range append([]string{name}, aliases...) { + // v1 -> v2 migration warning zone: + // Strip off anything after the first found comma or space, which + // *hopefully* makes it a tiny bit more obvious that unexpected behavior is + // caused by using the v1 form of stringly typed "Name". + ret = append(ret, commaWhitespace.ReplaceAllString(part, "")) + } + + return ret +} + +func flagStringSliceField(f Flag, name string) []string { + fv := flagValue(f) + field := fv.FieldByName(name) + + if field.IsValid() { + return field.Interface().([]string) + } + + return []string{} +} + +func flagStringField(f Flag, name string) string { + fv := flagValue(f) + field := fv.FieldByName(name) + + if field.IsValid() { + return field.String() + } + + return "" +} + func withFileHint(filePath, str string) string { fileText := "" if filePath != "" { @@ -221,39 +262,27 @@ func stringifyFlag(f Flag) string { fv := flagValue(f) switch f.(type) { - case IntSliceFlag: - return FlagFileHinter( - fv.FieldByName("FilePath").String(), - FlagEnvHinter( - fv.FieldByName("EnvVar").String(), - stringifyIntSliceFlag(f.(IntSliceFlag)), - ), - ) - case Int64SliceFlag: - return FlagFileHinter( - fv.FieldByName("FilePath").String(), - FlagEnvHinter( - fv.FieldByName("EnvVar").String(), - stringifyInt64SliceFlag(f.(Int64SliceFlag)), - ), - ) - case StringSliceFlag: - return FlagFileHinter( - fv.FieldByName("FilePath").String(), - FlagEnvHinter( - fv.FieldByName("EnvVar").String(), - stringifyStringSliceFlag(f.(StringSliceFlag)), - ), - ) + case *IntSliceFlag: + return withEnvHint(flagStringSliceField(f, "EnvVars"), + stringifyIntSliceFlag(f.(*IntSliceFlag))) + case *Int64SliceFlag: + return withEnvHint(flagStringSliceField(f, "EnvVars"), + stringifyInt64SliceFlag(f.(*Int64SliceFlag))) + case *Float64SliceFlag: + return withEnvHint(flagStringSliceField(f, "EnvVars"), + stringifyFloat64SliceFlag(f.(*Float64SliceFlag))) + case *StringSliceFlag: + return withEnvHint(flagStringSliceField(f, "EnvVars"), + stringifyStringSliceFlag(f.(*StringSliceFlag))) } placeholder, usage := unquoteUsage(fv.FieldByName("Usage").String()) needsPlaceholder := false defaultValueString := "" - - if val := fv.FieldByName("Value"); val.IsValid() { - needsPlaceholder = true + val := fv.FieldByName("Value") + if val.IsValid() { + needsPlaceholder = val.Kind() != reflect.Bool defaultValueString = fmt.Sprintf(" (default: %v)", val.Interface()) if val.Kind() == reflect.String && val.String() != "" { @@ -261,6 +290,12 @@ func stringifyFlag(f Flag) string { } } + helpText := fv.FieldByName("DefaultText") + if helpText.IsValid() && helpText.String() != "" { + needsPlaceholder = val.Kind() != reflect.Bool + defaultValueString = fmt.Sprintf(" (default: %s)", helpText.String()) + } + if defaultValueString == " (default: )" { defaultValueString = "" } @@ -271,16 +306,11 @@ func stringifyFlag(f Flag) string { usageWithDefault := strings.TrimSpace(usage + defaultValueString) - return FlagFileHinter( - fv.FieldByName("FilePath").String(), - FlagEnvHinter( - fv.FieldByName("EnvVar").String(), - FlagNamePrefixer(fv.FieldByName("Name").String(), placeholder)+"\t"+usageWithDefault, - ), - ) + return withEnvHint(flagStringSliceField(f, "EnvVars"), + fmt.Sprintf("%s\t%s", prefixedNames(f.Names(), placeholder), usageWithDefault)) } -func stringifyIntSliceFlag(f IntSliceFlag) string { +func stringifyIntSliceFlag(f *IntSliceFlag) string { var defaultVals []string if f.Value != nil && len(f.Value.Value()) > 0 { for _, i := range f.Value.Value() { @@ -288,10 +318,10 @@ func stringifyIntSliceFlag(f IntSliceFlag) string { } } - return stringifySliceFlag(f.Usage, f.Name, defaultVals) + return stringifySliceFlag(f.Usage, f.Names(), defaultVals) } -func stringifyInt64SliceFlag(f Int64SliceFlag) string { +func stringifyInt64SliceFlag(f *Int64SliceFlag) string { var defaultVals []string if f.Value != nil && len(f.Value.Value()) > 0 { for _, i := range f.Value.Value() { @@ -299,10 +329,22 @@ func stringifyInt64SliceFlag(f Int64SliceFlag) string { } } - return stringifySliceFlag(f.Usage, f.Name, defaultVals) + return stringifySliceFlag(f.Usage, f.Names(), defaultVals) +} + +func stringifyFloat64SliceFlag(f *Float64SliceFlag) string { + var defaultVals []string + + if f.Value != nil && len(f.Value.Value()) > 0 { + for _, i := range f.Value.Value() { + defaultVals = append(defaultVals, strings.TrimRight(strings.TrimRight(fmt.Sprintf("%f", i), "0"), ".")) + } + } + + return stringifySliceFlag(f.Usage, f.Names(), defaultVals) } -func stringifyStringSliceFlag(f StringSliceFlag) string { +func stringifyStringSliceFlag(f *StringSliceFlag) string { var defaultVals []string if f.Value != nil && len(f.Value.Value()) > 0 { for _, s := range f.Value.Value() { @@ -312,10 +354,10 @@ func stringifyStringSliceFlag(f StringSliceFlag) string { } } - return stringifySliceFlag(f.Usage, f.Name, defaultVals) + return stringifySliceFlag(f.Usage, f.Names(), defaultVals) } -func stringifySliceFlag(usage, name string, defaultVals []string) string { +func stringifySliceFlag(usage string, names, defaultVals []string) string { placeholder, usage := unquoteUsage(usage) if placeholder == "" { placeholder = defaultPlaceholder @@ -326,15 +368,25 @@ func stringifySliceFlag(usage, name string, defaultVals []string) string { defaultVal = fmt.Sprintf(" (default: %s)", strings.Join(defaultVals, ", ")) } - usageWithDefault := strings.TrimSpace(usage + defaultVal) - return FlagNamePrefixer(name, placeholder) + "\t" + usageWithDefault + usageWithDefault := strings.TrimSpace(fmt.Sprintf("%s%s", usage, defaultVal)) + return fmt.Sprintf("%s\t%s", prefixedNames(names, placeholder), usageWithDefault) +} + +func hasFlag(flags []Flag, fl Flag) bool { + for _, existing := range flags { + if fl == existing { + return true + } + } + + return false } -func flagFromFileEnv(filePath, envName string) (val string, ok bool) { - for _, envVar := range strings.Split(envName, ",") { +func flagFromEnvOrFile(envVars []string, filePath string) (val string, ok bool) { + for _, envVar := range envVars { envVar = strings.TrimSpace(envVar) - if envVal, ok := syscall.Getenv(envVar); ok { - return envVal, true + if val, ok := syscall.Getenv(envVar); ok { + return val, true } } for _, fileVar := range strings.Split(filePath, ",") { diff --git a/vendor/github.com/urfave/cli/flag_bool.go b/vendor/github.com/urfave/cli/v2/flag_bool.go similarity index 51% rename from vendor/github.com/urfave/cli/flag_bool.go rename to vendor/github.com/urfave/cli/v2/flag_bool.go index 2499b0b524..6a1da61efd 100644 --- a/vendor/github.com/urfave/cli/flag_bool.go +++ b/vendor/github.com/urfave/cli/v2/flag_bool.go @@ -9,93 +9,90 @@ import ( // BoolFlag is a flag with type bool type BoolFlag struct { Name string + Aliases []string Usage string - EnvVar string + EnvVars []string FilePath string Required bool Hidden bool + Value bool + DefaultText string Destination *bool + HasBeenSet bool +} + +// IsSet returns whether or not the flag has been set through env or file +func (f *BoolFlag) IsSet() bool { + return f.HasBeenSet } // String returns a readable representation of this value // (for usage defaults) -func (f BoolFlag) String() string { +func (f *BoolFlag) String() string { return FlagStringer(f) } -// GetName returns the name of the flag -func (f BoolFlag) GetName() string { - return f.Name +// Names returns the names of the flag +func (f *BoolFlag) Names() []string { + return flagNames(f) } // IsRequired returns whether or not the flag is required -func (f BoolFlag) IsRequired() bool { +func (f *BoolFlag) IsRequired() bool { return f.Required } // TakesValue returns true of the flag takes a value, otherwise false -func (f BoolFlag) TakesValue() bool { +func (f *BoolFlag) TakesValue() bool { return false } // GetUsage returns the usage string for the flag -func (f BoolFlag) GetUsage() string { +func (f *BoolFlag) GetUsage() string { return f.Usage } // GetValue returns the flags value as string representation and an empty // string if the flag takes no value at all. -func (f BoolFlag) GetValue() string { +func (f *BoolFlag) GetValue() string { return "" } -// Bool looks up the value of a local BoolFlag, returns -// false if not found -func (c *Context) Bool(name string) bool { - return lookupBool(name, c.flagSet) -} - -// GlobalBool looks up the value of a global BoolFlag, returns -// false if not found -func (c *Context) GlobalBool(name string) bool { - if fs := lookupGlobalFlagSet(name, c); fs != nil { - return lookupBool(name, fs) - } - return false -} - // Apply populates the flag given the flag set and environment -// Ignores errors -func (f BoolFlag) Apply(set *flag.FlagSet) { - _ = f.ApplyWithError(set) -} +func (f *BoolFlag) Apply(set *flag.FlagSet) error { + if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { + if val != "" { + valBool, err := strconv.ParseBool(val) -// ApplyWithError populates the flag given the flag set and environment -func (f BoolFlag) ApplyWithError(set *flag.FlagSet) error { - val := false - if envVal, ok := flagFromFileEnv(f.FilePath, f.EnvVar); ok { - if envVal == "" { - val = false - } else { - envValBool, err := strconv.ParseBool(envVal) if err != nil { - return fmt.Errorf("could not parse %s as bool value for flag %s: %s", envVal, f.Name, err) + return fmt.Errorf("could not parse %q as bool value for flag %s: %s", val, f.Name, err) } - val = envValBool + + f.Value = valBool + f.HasBeenSet = true } } - eachName(f.Name, func(name string) { + for _, name := range f.Names() { if f.Destination != nil { - set.BoolVar(f.Destination, name, val, f.Usage) - return + set.BoolVar(f.Destination, name, f.Value, f.Usage) + continue } - set.Bool(name, val, f.Usage) - }) + set.Bool(name, f.Value, f.Usage) + } return nil } +// Bool looks up the value of a local BoolFlag, returns +// false if not found +func (c *Context) Bool(name string) bool { + if fs := lookupFlagSet(name, c); fs != nil { + return lookupBool(name, fs) + } + return false +} + func lookupBool(name string, set *flag.FlagSet) bool { f := set.Lookup(name) if f != nil { diff --git a/vendor/github.com/urfave/cli/flag_duration.go b/vendor/github.com/urfave/cli/v2/flag_duration.go similarity index 56% rename from vendor/github.com/urfave/cli/flag_duration.go rename to vendor/github.com/urfave/cli/v2/flag_duration.go index df4ade589d..2c34944a4b 100644 --- a/vendor/github.com/urfave/cli/flag_duration.go +++ b/vendor/github.com/urfave/cli/v2/flag_duration.go @@ -9,90 +9,89 @@ import ( // DurationFlag is a flag with type time.Duration (see https://golang.org/pkg/time/#ParseDuration) type DurationFlag struct { Name string + Aliases []string Usage string - EnvVar string + EnvVars []string FilePath string Required bool Hidden bool Value time.Duration + DefaultText string Destination *time.Duration + HasBeenSet bool +} + +// IsSet returns whether or not the flag has been set through env or file +func (f *DurationFlag) IsSet() bool { + return f.HasBeenSet } // String returns a readable representation of this value // (for usage defaults) -func (f DurationFlag) String() string { +func (f *DurationFlag) String() string { return FlagStringer(f) } -// GetName returns the name of the flag -func (f DurationFlag) GetName() string { - return f.Name +// Names returns the names of the flag +func (f *DurationFlag) Names() []string { + return flagNames(f) } // IsRequired returns whether or not the flag is required -func (f DurationFlag) IsRequired() bool { +func (f *DurationFlag) IsRequired() bool { return f.Required } // TakesValue returns true of the flag takes a value, otherwise false -func (f DurationFlag) TakesValue() bool { +func (f *DurationFlag) TakesValue() bool { return true } // GetUsage returns the usage string for the flag -func (f DurationFlag) GetUsage() string { +func (f *DurationFlag) GetUsage() string { return f.Usage } // GetValue returns the flags value as string representation and an empty // string if the flag takes no value at all. -func (f DurationFlag) GetValue() string { +func (f *DurationFlag) GetValue() string { return f.Value.String() } -// Duration looks up the value of a local DurationFlag, returns -// 0 if not found -func (c *Context) Duration(name string) time.Duration { - return lookupDuration(name, c.flagSet) -} - -// GlobalDuration looks up the value of a global DurationFlag, returns -// 0 if not found -func (c *Context) GlobalDuration(name string) time.Duration { - if fs := lookupGlobalFlagSet(name, c); fs != nil { - return lookupDuration(name, fs) - } - return 0 -} - // Apply populates the flag given the flag set and environment -// Ignores errors -func (f DurationFlag) Apply(set *flag.FlagSet) { - _ = f.ApplyWithError(set) -} +func (f *DurationFlag) Apply(set *flag.FlagSet) error { + if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { + if val != "" { + valDuration, err := time.ParseDuration(val) -// ApplyWithError populates the flag given the flag set and environment -func (f DurationFlag) ApplyWithError(set *flag.FlagSet) error { - if envVal, ok := flagFromFileEnv(f.FilePath, f.EnvVar); ok { - envValDuration, err := time.ParseDuration(envVal) - if err != nil { - return fmt.Errorf("could not parse %s as duration for flag %s: %s", envVal, f.Name, err) - } + if err != nil { + return fmt.Errorf("could not parse %q as duration value for flag %s: %s", val, f.Name, err) + } - f.Value = envValDuration + f.Value = valDuration + f.HasBeenSet = true + } } - eachName(f.Name, func(name string) { + for _, name := range f.Names() { if f.Destination != nil { set.DurationVar(f.Destination, name, f.Value, f.Usage) - return + continue } set.Duration(name, f.Value, f.Usage) - }) - + } return nil } +// Duration looks up the value of a local DurationFlag, returns +// 0 if not found +func (c *Context) Duration(name string) time.Duration { + if fs := lookupFlagSet(name, c); fs != nil { + return lookupDuration(name, fs) + } + return 0 +} + func lookupDuration(name string, set *flag.FlagSet) time.Duration { f := set.Lookup(name) if f != nil { diff --git a/vendor/github.com/urfave/cli/flag_float64.go b/vendor/github.com/urfave/cli/v2/flag_float64.go similarity index 56% rename from vendor/github.com/urfave/cli/flag_float64.go rename to vendor/github.com/urfave/cli/v2/flag_float64.go index 65398d3b5c..228554715a 100644 --- a/vendor/github.com/urfave/cli/flag_float64.go +++ b/vendor/github.com/urfave/cli/v2/flag_float64.go @@ -9,90 +9,90 @@ import ( // Float64Flag is a flag with type float64 type Float64Flag struct { Name string + Aliases []string Usage string - EnvVar string + EnvVars []string FilePath string Required bool Hidden bool Value float64 + DefaultText string Destination *float64 + HasBeenSet bool +} + +// IsSet returns whether or not the flag has been set through env or file +func (f *Float64Flag)IsSet() bool { + return f.HasBeenSet } // String returns a readable representation of this value // (for usage defaults) -func (f Float64Flag) String() string { +func (f *Float64Flag) String() string { return FlagStringer(f) } -// GetName returns the name of the flag -func (f Float64Flag) GetName() string { - return f.Name +// Names returns the names of the flag +func (f *Float64Flag) Names() []string { + return flagNames(f) } // IsRequired returns whether or not the flag is required -func (f Float64Flag) IsRequired() bool { +func (f *Float64Flag) IsRequired() bool { return f.Required } // TakesValue returns true of the flag takes a value, otherwise false -func (f Float64Flag) TakesValue() bool { +func (f *Float64Flag) TakesValue() bool { return true } // GetUsage returns the usage string for the flag -func (f Float64Flag) GetUsage() string { +func (f *Float64Flag) GetUsage() string { return f.Usage } // GetValue returns the flags value as string representation and an empty // string if the flag takes no value at all. -func (f Float64Flag) GetValue() string { +func (f *Float64Flag) GetValue() string { return fmt.Sprintf("%f", f.Value) } -// Float64 looks up the value of a local Float64Flag, returns -// 0 if not found -func (c *Context) Float64(name string) float64 { - return lookupFloat64(name, c.flagSet) -} - -// GlobalFloat64 looks up the value of a global Float64Flag, returns -// 0 if not found -func (c *Context) GlobalFloat64(name string) float64 { - if fs := lookupGlobalFlagSet(name, c); fs != nil { - return lookupFloat64(name, fs) - } - return 0 -} - // Apply populates the flag given the flag set and environment -// Ignores errors -func (f Float64Flag) Apply(set *flag.FlagSet) { - _ = f.ApplyWithError(set) -} +func (f *Float64Flag) Apply(set *flag.FlagSet) error { + if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { + if val != "" { + valFloat, err := strconv.ParseFloat(val, 10) -// ApplyWithError populates the flag given the flag set and environment -func (f Float64Flag) ApplyWithError(set *flag.FlagSet) error { - if envVal, ok := flagFromFileEnv(f.FilePath, f.EnvVar); ok { - envValFloat, err := strconv.ParseFloat(envVal, 10) - if err != nil { - return fmt.Errorf("could not parse %s as float64 value for flag %s: %s", envVal, f.Name, err) - } + if err != nil { + return fmt.Errorf("could not parse %q as float64 value for flag %s: %s", val, f.Name, err) + } - f.Value = envValFloat + f.Value = valFloat + f.HasBeenSet = true + } } - eachName(f.Name, func(name string) { + for _, name := range f.Names() { if f.Destination != nil { set.Float64Var(f.Destination, name, f.Value, f.Usage) - return + continue } set.Float64(name, f.Value, f.Usage) - }) + } return nil } +// Float64 looks up the value of a local Float64Flag, returns +// 0 if not found +func (c *Context) Float64(name string) float64 { + if fs := lookupFlagSet(name, c); fs != nil { + return lookupFloat64(name, fs) + } + return 0 +} + func lookupFloat64(name string, set *flag.FlagSet) float64 { f := set.Lookup(name) if f != nil { diff --git a/vendor/github.com/urfave/cli/v2/flag_float64_slice.go b/vendor/github.com/urfave/cli/v2/flag_float64_slice.go new file mode 100644 index 0000000000..91d2e9d100 --- /dev/null +++ b/vendor/github.com/urfave/cli/v2/flag_float64_slice.go @@ -0,0 +1,165 @@ +package cli + +import ( + "encoding/json" + "flag" + "fmt" + "strconv" + "strings" +) + +// Float64Slice wraps []float64 to satisfy flag.Value +type Float64Slice struct { + slice []float64 + hasBeenSet bool +} + +// NewFloat64Slice makes a *Float64Slice with default values +func NewFloat64Slice(defaults ...float64) *Float64Slice { + return &Float64Slice{slice: append([]float64{}, defaults...)} +} + +// Set parses the value into a float64 and appends it to the list of values +func (f *Float64Slice) Set(value string) error { + if !f.hasBeenSet { + f.slice = []float64{} + f.hasBeenSet = true + } + + if strings.HasPrefix(value, slPfx) { + // Deserializing assumes overwrite + _ = json.Unmarshal([]byte(strings.Replace(value, slPfx, "", 1)), &f.slice) + f.hasBeenSet = true + return nil + } + + tmp, err := strconv.ParseFloat(value, 64) + if err != nil { + return err + } + + f.slice = append(f.slice, tmp) + return nil +} + +// String returns a readable representation of this value (for usage defaults) +func (f *Float64Slice) String() string { + return fmt.Sprintf("%#v", f.slice) +} + +// Serialize allows Float64Slice to fulfill Serializer +func (f *Float64Slice) Serialize() string { + jsonBytes, _ := json.Marshal(f.slice) + return fmt.Sprintf("%s%s", slPfx, string(jsonBytes)) +} + +// Value returns the slice of float64s set by this flag +func (f *Float64Slice) Value() []float64 { + return f.slice +} + +// Get returns the slice of float64s set by this flag +func (f *Float64Slice) Get() interface{} { + return *f +} + +// Float64SliceFlag is a flag with type *Float64Slice +type Float64SliceFlag struct { + Name string + Aliases []string + Usage string + EnvVars []string + FilePath string + Required bool + Hidden bool + Value *Float64Slice + DefaultText string + HasBeenSet bool +} + +// IsSet returns whether or not the flag has been set through env or file +func (f *Float64SliceFlag) IsSet() bool { + return f.HasBeenSet +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f *Float64SliceFlag) String() string { + return FlagStringer(f) +} + +// Names returns the names of the flag +func (f *Float64SliceFlag) Names() []string { + return flagNames(f) +} + +// IsRequired returns whether or not the flag is required +func (f *Float64SliceFlag) IsRequired() bool { + return f.Required +} + +// TakesValue returns true if the flag takes a value, otherwise false +func (f *Float64SliceFlag) TakesValue() bool { + return true +} + +// GetUsage returns the usage string for the flag +func (f *Float64SliceFlag) GetUsage() string { + return f.Usage +} + +// GetValue returns the flags value as string representation and an empty +// string if the flag takes no value at all. +func (f *Float64SliceFlag) GetValue() string { + if f.Value != nil { + return f.Value.String() + } + return "" +} + +// Apply populates the flag given the flag set and environment +func (f *Float64SliceFlag) Apply(set *flag.FlagSet) error { + if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { + if val != "" { + f.Value = &Float64Slice{} + + for _, s := range strings.Split(val, ",") { + if err := f.Value.Set(strings.TrimSpace(s)); err != nil { + return fmt.Errorf("could not parse %q as float64 slice value for flag %s: %s", f.Value, f.Name, err) + } + } + + f.HasBeenSet = true + } + } + + for _, name := range f.Names() { + if f.Value == nil { + f.Value = &Float64Slice{} + } + set.Var(f.Value, name, f.Usage) + } + + return nil +} + +// Float64Slice looks up the value of a local Float64SliceFlag, returns +// nil if not found +func (c *Context) Float64Slice(name string) []float64 { + if fs := lookupFlagSet(name, c); fs != nil { + return lookupFloat64Slice(name, fs) + } + return nil +} + +func lookupFloat64Slice(name string, set *flag.FlagSet) []float64 { + f := set.Lookup(name) + if f != nil { + parsed, err := (f.Value.(*Float64Slice)).Value(), error(nil) + if err != nil { + return nil + } + return parsed + } + return nil +} diff --git a/vendor/github.com/urfave/cli/flag_generic.go b/vendor/github.com/urfave/cli/v2/flag_generic.go similarity index 52% rename from vendor/github.com/urfave/cli/flag_generic.go rename to vendor/github.com/urfave/cli/v2/flag_generic.go index c43dae7d0b..2d9baa78de 100644 --- a/vendor/github.com/urfave/cli/flag_generic.go +++ b/vendor/github.com/urfave/cli/v2/flag_generic.go @@ -13,45 +13,53 @@ type Generic interface { // GenericFlag is a flag with type Generic type GenericFlag struct { - Name string - Usage string - EnvVar string - FilePath string - Required bool - Hidden bool - TakesFile bool - Value Generic + Name string + Aliases []string + Usage string + EnvVars []string + FilePath string + Required bool + Hidden bool + TakesFile bool + Value Generic + DefaultText string + HasBeenSet bool +} + +// IsSet returns whether or not the flag has been set through env or file +func (f *GenericFlag) IsSet() bool { + return f.HasBeenSet } // String returns a readable representation of this value // (for usage defaults) -func (f GenericFlag) String() string { +func (f *GenericFlag) String() string { return FlagStringer(f) } -// GetName returns the name of the flag -func (f GenericFlag) GetName() string { - return f.Name +// Names returns the names of the flag +func (f *GenericFlag) Names() []string { + return flagNames(f) } // IsRequired returns whether or not the flag is required -func (f GenericFlag) IsRequired() bool { +func (f *GenericFlag) IsRequired() bool { return f.Required } // TakesValue returns true of the flag takes a value, otherwise false -func (f GenericFlag) TakesValue() bool { +func (f *GenericFlag) TakesValue() bool { return true } // GetUsage returns the usage string for the flag -func (f GenericFlag) GetUsage() string { +func (f *GenericFlag) GetUsage() string { return f.Usage } // GetValue returns the flags value as string representation and an empty // string if the flag takes no value at all. -func (f GenericFlag) GetValue() string { +func (f *GenericFlag) GetValue() string { if f.Value != nil { return f.Value.String() } @@ -60,24 +68,20 @@ func (f GenericFlag) GetValue() string { // Apply takes the flagset and calls Set on the generic flag with the value // provided by the user for parsing by the flag -// Ignores parsing errors -func (f GenericFlag) Apply(set *flag.FlagSet) { - _ = f.ApplyWithError(set) -} - -// ApplyWithError takes the flagset and calls Set on the generic flag with the value -// provided by the user for parsing by the flag -func (f GenericFlag) ApplyWithError(set *flag.FlagSet) error { - val := f.Value - if fileEnvVal, ok := flagFromFileEnv(f.FilePath, f.EnvVar); ok { - if err := val.Set(fileEnvVal); err != nil { - return fmt.Errorf("could not parse %s as value for flag %s: %s", fileEnvVal, f.Name, err) +func (f GenericFlag) Apply(set *flag.FlagSet) error { + if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { + if val != "" { + if err := f.Value.Set(val); err != nil { + return fmt.Errorf("could not parse %q as value for flag %s: %s", val, f.Name, err) + } + + f.HasBeenSet = true } } - eachName(f.Name, func(name string) { + for _, name := range f.Names() { set.Var(f.Value, name, f.Usage) - }) + } return nil } @@ -85,13 +89,7 @@ func (f GenericFlag) ApplyWithError(set *flag.FlagSet) error { // Generic looks up the value of a local GenericFlag, returns // nil if not found func (c *Context) Generic(name string) interface{} { - return lookupGeneric(name, c.flagSet) -} - -// GlobalGeneric looks up the value of a global GenericFlag, returns -// nil if not found -func (c *Context) GlobalGeneric(name string) interface{} { - if fs := lookupGlobalFlagSet(name, c); fs != nil { + if fs := lookupFlagSet(name, c); fs != nil { return lookupGeneric(name, fs) } return nil diff --git a/vendor/github.com/urfave/cli/flag_int.go b/vendor/github.com/urfave/cli/v2/flag_int.go similarity index 56% rename from vendor/github.com/urfave/cli/flag_int.go rename to vendor/github.com/urfave/cli/v2/flag_int.go index bae32e2818..be961bf5f1 100644 --- a/vendor/github.com/urfave/cli/flag_int.go +++ b/vendor/github.com/urfave/cli/v2/flag_int.go @@ -9,70 +9,77 @@ import ( // IntFlag is a flag with type int type IntFlag struct { Name string + Aliases []string Usage string - EnvVar string + EnvVars []string FilePath string Required bool Hidden bool Value int + DefaultText string Destination *int + HasBeenSet bool +} + +// IsSet returns whether or not the flag has been set through env or file +func (f *IntFlag) IsSet() bool { + return f.HasBeenSet } // String returns a readable representation of this value // (for usage defaults) -func (f IntFlag) String() string { +func (f *IntFlag) String() string { return FlagStringer(f) } -// GetName returns the name of the flag -func (f IntFlag) GetName() string { - return f.Name +// Names returns the names of the flag +func (f *IntFlag) Names() []string { + return flagNames(f) } // IsRequired returns whether or not the flag is required -func (f IntFlag) IsRequired() bool { +func (f *IntFlag) IsRequired() bool { return f.Required } // TakesValue returns true of the flag takes a value, otherwise false -func (f IntFlag) TakesValue() bool { +func (f *IntFlag) TakesValue() bool { return true } // GetUsage returns the usage string for the flag -func (f IntFlag) GetUsage() string { +func (f *IntFlag) GetUsage() string { return f.Usage } // GetValue returns the flags value as string representation and an empty // string if the flag takes no value at all. -func (f IntFlag) GetValue() string { +func (f *IntFlag) GetValue() string { return fmt.Sprintf("%d", f.Value) } // Apply populates the flag given the flag set and environment -// Ignores errors -func (f IntFlag) Apply(set *flag.FlagSet) { - _ = f.ApplyWithError(set) -} +func (f *IntFlag) Apply(set *flag.FlagSet) error { + if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { + if val != "" { + valInt, err := strconv.ParseInt(val, 0, 64) -// ApplyWithError populates the flag given the flag set and environment -func (f IntFlag) ApplyWithError(set *flag.FlagSet) error { - if envVal, ok := flagFromFileEnv(f.FilePath, f.EnvVar); ok { - envValInt, err := strconv.ParseInt(envVal, 0, 64) - if err != nil { - return fmt.Errorf("could not parse %s as int value for flag %s: %s", envVal, f.Name, err) + if err != nil { + return fmt.Errorf("could not parse %q as int value for flag %s: %s", val, f.Name, err) + } + + f.Value = int(valInt) + f.HasBeenSet = true } - f.Value = int(envValInt) } - eachName(f.Name, func(name string) { + for _, name := range f.Names() { if f.Destination != nil { set.IntVar(f.Destination, name, f.Value, f.Usage) - return + continue } set.Int(name, f.Value, f.Usage) - }) + } return nil } @@ -80,13 +87,7 @@ func (f IntFlag) ApplyWithError(set *flag.FlagSet) error { // Int looks up the value of a local IntFlag, returns // 0 if not found func (c *Context) Int(name string) int { - return lookupInt(name, c.flagSet) -} - -// GlobalInt looks up the value of a global IntFlag, returns -// 0 if not found -func (c *Context) GlobalInt(name string) int { - if fs := lookupGlobalFlagSet(name, c); fs != nil { + if fs := lookupFlagSet(name, c); fs != nil { return lookupInt(name, fs) } return 0 diff --git a/vendor/github.com/urfave/cli/flag_int64.go b/vendor/github.com/urfave/cli/v2/flag_int64.go similarity index 56% rename from vendor/github.com/urfave/cli/flag_int64.go rename to vendor/github.com/urfave/cli/v2/flag_int64.go index aaafbe9d6d..c979119f8e 100644 --- a/vendor/github.com/urfave/cli/flag_int64.go +++ b/vendor/github.com/urfave/cli/v2/flag_int64.go @@ -9,85 +9,84 @@ import ( // Int64Flag is a flag with type int64 type Int64Flag struct { Name string + Aliases []string Usage string - EnvVar string + EnvVars []string FilePath string Required bool Hidden bool Value int64 + DefaultText string Destination *int64 + HasBeenSet bool +} + +// IsSet returns whether or not the flag has been set through env or file +func (f *Int64Flag) IsSet() bool { + return f.HasBeenSet } // String returns a readable representation of this value // (for usage defaults) -func (f Int64Flag) String() string { +func (f *Int64Flag) String() string { return FlagStringer(f) } -// GetName returns the name of the flag -func (f Int64Flag) GetName() string { - return f.Name +// Names returns the names of the flag +func (f *Int64Flag) Names() []string { + return flagNames(f) } // IsRequired returns whether or not the flag is required -func (f Int64Flag) IsRequired() bool { +func (f *Int64Flag) IsRequired() bool { return f.Required } // TakesValue returns true of the flag takes a value, otherwise false -func (f Int64Flag) TakesValue() bool { +func (f *Int64Flag) TakesValue() bool { return true } // GetUsage returns the usage string for the flag -func (f Int64Flag) GetUsage() string { +func (f *Int64Flag) GetUsage() string { return f.Usage } // GetValue returns the flags value as string representation and an empty // string if the flag takes no value at all. -func (f Int64Flag) GetValue() string { +func (f *Int64Flag) GetValue() string { return fmt.Sprintf("%d", f.Value) } // Apply populates the flag given the flag set and environment -// Ignores errors -func (f Int64Flag) Apply(set *flag.FlagSet) { - _ = f.ApplyWithError(set) -} +func (f *Int64Flag) Apply(set *flag.FlagSet) error { + if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { + if val != "" { + valInt, err := strconv.ParseInt(val, 0, 64) -// ApplyWithError populates the flag given the flag set and environment -func (f Int64Flag) ApplyWithError(set *flag.FlagSet) error { - if envVal, ok := flagFromFileEnv(f.FilePath, f.EnvVar); ok { - envValInt, err := strconv.ParseInt(envVal, 0, 64) - if err != nil { - return fmt.Errorf("could not parse %s as int value for flag %s: %s", envVal, f.Name, err) - } + if err != nil { + return fmt.Errorf("could not parse %q as int value for flag %s: %s", val, f.Name, err) + } - f.Value = envValInt + f.Value = valInt + f.HasBeenSet = true + } } - eachName(f.Name, func(name string) { + for _, name := range f.Names() { if f.Destination != nil { set.Int64Var(f.Destination, name, f.Value, f.Usage) - return + continue } set.Int64(name, f.Value, f.Usage) - }) - + } return nil } // Int64 looks up the value of a local Int64Flag, returns // 0 if not found func (c *Context) Int64(name string) int64 { - return lookupInt64(name, c.flagSet) -} - -// GlobalInt64 looks up the value of a global Int64Flag, returns -// 0 if not found -func (c *Context) GlobalInt64(name string) int64 { - if fs := lookupGlobalFlagSet(name, c); fs != nil { + if fs := lookupFlagSet(name, c); fs != nil { return lookupInt64(name, fs) } return 0 diff --git a/vendor/github.com/urfave/cli/v2/flag_int64_slice.go b/vendor/github.com/urfave/cli/v2/flag_int64_slice.go new file mode 100644 index 0000000000..41aa0667e6 --- /dev/null +++ b/vendor/github.com/urfave/cli/v2/flag_int64_slice.go @@ -0,0 +1,161 @@ +package cli + +import ( + "encoding/json" + "flag" + "fmt" + "strconv" + "strings" +) + +// Int64Slice wraps []int64 to satisfy flag.Value +type Int64Slice struct { + slice []int64 + hasBeenSet bool +} + +// NewInt64Slice makes an *Int64Slice with default values +func NewInt64Slice(defaults ...int64) *Int64Slice { + return &Int64Slice{slice: append([]int64{}, defaults...)} +} + +// Set parses the value into an integer and appends it to the list of values +func (i *Int64Slice) Set(value string) error { + if !i.hasBeenSet { + i.slice = []int64{} + i.hasBeenSet = true + } + + if strings.HasPrefix(value, slPfx) { + // Deserializing assumes overwrite + _ = json.Unmarshal([]byte(strings.Replace(value, slPfx, "", 1)), &i.slice) + i.hasBeenSet = true + return nil + } + + tmp, err := strconv.ParseInt(value, 0, 64) + if err != nil { + return err + } + + i.slice = append(i.slice, tmp) + + return nil +} + +// String returns a readable representation of this value (for usage defaults) +func (i *Int64Slice) String() string { + return fmt.Sprintf("%#v", i.slice) +} + +// Serialize allows Int64Slice to fulfill Serializer +func (i *Int64Slice) Serialize() string { + jsonBytes, _ := json.Marshal(i.slice) + return fmt.Sprintf("%s%s", slPfx, string(jsonBytes)) +} + +// Value returns the slice of ints set by this flag +func (i *Int64Slice) Value() []int64 { + return i.slice +} + +// Get returns the slice of ints set by this flag +func (i *Int64Slice) Get() interface{} { + return *i +} + +// Int64SliceFlag is a flag with type *Int64Slice +type Int64SliceFlag struct { + Name string + Aliases []string + Usage string + EnvVars []string + FilePath string + Required bool + Hidden bool + Value *Int64Slice + DefaultText string + HasBeenSet bool +} + +// IsSet returns whether or not the flag has been set through env or file +func (f *Int64SliceFlag) IsSet() bool { + return f.HasBeenSet +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f *Int64SliceFlag) String() string { + return FlagStringer(f) +} + +// Names returns the names of the flag +func (f *Int64SliceFlag) Names() []string { + return flagNames(f) +} + +// IsRequired returns whether or not the flag is required +func (f *Int64SliceFlag) IsRequired() bool { + return f.Required +} + +// TakesValue returns true of the flag takes a value, otherwise false +func (f *Int64SliceFlag) TakesValue() bool { + return true +} + +// GetUsage returns the usage string for the flag +func (f Int64SliceFlag) GetUsage() string { + return f.Usage +} + +// GetValue returns the flags value as string representation and an empty +// string if the flag takes no value at all. +func (f *Int64SliceFlag) GetValue() string { + if f.Value != nil { + return f.Value.String() + } + return "" +} + +// Apply populates the flag given the flag set and environment +func (f *Int64SliceFlag) Apply(set *flag.FlagSet) error { + if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { + f.Value = &Int64Slice{} + + for _, s := range strings.Split(val, ",") { + if err := f.Value.Set(strings.TrimSpace(s)); err != nil { + return fmt.Errorf("could not parse %q as int64 slice value for flag %s: %s", val, f.Name, err) + } + } + + f.HasBeenSet = true + } + + for _, name := range f.Names() { + if f.Value == nil { + f.Value = &Int64Slice{} + } + set.Var(f.Value, name, f.Usage) + } + + return nil +} + +// Int64Slice looks up the value of a local Int64SliceFlag, returns +// nil if not found +func (c *Context) Int64Slice(name string) []int64 { + return lookupInt64Slice(name, c.flagSet) +} + +func lookupInt64Slice(name string, set *flag.FlagSet) []int64 { + f := set.Lookup(name) + if f != nil { + parsed, err := (f.Value.(*Int64Slice)).Value(), error(nil) + if err != nil { + return nil + } + return parsed + } + return nil +} diff --git a/vendor/github.com/urfave/cli/v2/flag_int_slice.go b/vendor/github.com/urfave/cli/v2/flag_int_slice.go new file mode 100644 index 0000000000..9388978421 --- /dev/null +++ b/vendor/github.com/urfave/cli/v2/flag_int_slice.go @@ -0,0 +1,175 @@ +package cli + +import ( + "encoding/json" + "flag" + "fmt" + "strconv" + "strings" +) + +// IntSlice wraps []int to satisfy flag.Value +type IntSlice struct { + slice []int + hasBeenSet bool +} + +// NewIntSlice makes an *IntSlice with default values +func NewIntSlice(defaults ...int) *IntSlice { + return &IntSlice{slice: append([]int{}, defaults...)} +} + +// TODO: Consistently have specific Set function for Int64 and Float64 ? +// SetInt directly adds an integer to the list of values +func (i *IntSlice) SetInt(value int) { + if !i.hasBeenSet { + i.slice = []int{} + i.hasBeenSet = true + } + + i.slice = append(i.slice, value) +} + +// Set parses the value into an integer and appends it to the list of values +func (i *IntSlice) Set(value string) error { + if !i.hasBeenSet { + i.slice = []int{} + i.hasBeenSet = true + } + + if strings.HasPrefix(value, slPfx) { + // Deserializing assumes overwrite + _ = json.Unmarshal([]byte(strings.Replace(value, slPfx, "", 1)), &i.slice) + i.hasBeenSet = true + return nil + } + + tmp, err := strconv.ParseInt(value, 0, 64) + if err != nil { + return err + } + + i.slice = append(i.slice, int(tmp)) + + return nil +} + +// String returns a readable representation of this value (for usage defaults) +func (i *IntSlice) String() string { + return fmt.Sprintf("%#v", i.slice) +} + +// Serialize allows IntSlice to fulfill Serializer +func (i *IntSlice) Serialize() string { + jsonBytes, _ := json.Marshal(i.slice) + return fmt.Sprintf("%s%s", slPfx, string(jsonBytes)) +} + +// Value returns the slice of ints set by this flag +func (i *IntSlice) Value() []int { + return i.slice +} + +// Get returns the slice of ints set by this flag +func (i *IntSlice) Get() interface{} { + return *i +} + +// IntSliceFlag is a flag with type *IntSlice +type IntSliceFlag struct { + Name string + Aliases []string + Usage string + EnvVars []string + FilePath string + Required bool + Hidden bool + Value *IntSlice + DefaultText string + HasBeenSet bool +} + +// IsSet returns whether or not the flag has been set through env or file +func (f *IntSliceFlag) IsSet() bool { + return f.HasBeenSet +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f *IntSliceFlag) String() string { + return FlagStringer(f) +} + +// Names returns the names of the flag +func (f *IntSliceFlag) Names() []string { + return flagNames(f) +} + +// IsRequired returns whether or not the flag is required +func (f *IntSliceFlag) IsRequired() bool { + return f.Required +} + +// TakesValue returns true of the flag takes a value, otherwise false +func (f *IntSliceFlag) TakesValue() bool { + return true +} + +// GetUsage returns the usage string for the flag +func (f IntSliceFlag) GetUsage() string { + return f.Usage +} + +// GetValue returns the flags value as string representation and an empty +// string if the flag takes no value at all. +func (f *IntSliceFlag) GetValue() string { + if f.Value != nil { + return f.Value.String() + } + return "" +} + +// Apply populates the flag given the flag set and environment +func (f *IntSliceFlag) Apply(set *flag.FlagSet) error { + if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { + f.Value = &IntSlice{} + + for _, s := range strings.Split(val, ",") { + if err := f.Value.Set(strings.TrimSpace(s)); err != nil { + return fmt.Errorf("could not parse %q as int slice value for flag %s: %s", val, f.Name, err) + } + } + + f.HasBeenSet = true + } + + for _, name := range f.Names() { + if f.Value == nil { + f.Value = &IntSlice{} + } + set.Var(f.Value, name, f.Usage) + } + + return nil +} + +// IntSlice looks up the value of a local IntSliceFlag, returns +// nil if not found +func (c *Context) IntSlice(name string) []int { + if fs := lookupFlagSet(name, c); fs != nil { + return lookupIntSlice(name, c.flagSet) + } + return nil +} + +func lookupIntSlice(name string, set *flag.FlagSet) []int { + f := set.Lookup(name) + if f != nil { + parsed, err := (f.Value.(*IntSlice)).Value(), error(nil) + if err != nil { + return nil + } + return parsed + } + return nil +} diff --git a/vendor/github.com/urfave/cli/v2/flag_path.go b/vendor/github.com/urfave/cli/v2/flag_path.go new file mode 100644 index 0000000000..d6b23c3c55 --- /dev/null +++ b/vendor/github.com/urfave/cli/v2/flag_path.go @@ -0,0 +1,95 @@ +package cli + +import "flag" + +type PathFlag struct { + Name string + Aliases []string + Usage string + EnvVars []string + FilePath string + Required bool + Hidden bool + TakesFile bool + Value string + DefaultText string + Destination *string + HasBeenSet bool +} + +// IsSet returns whether or not the flag has been set through env or file +func (f *PathFlag) IsSet() bool { + return f.HasBeenSet +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f *PathFlag) String() string { + return FlagStringer(f) +} + +// Names returns the names of the flag +func (f *PathFlag) Names() []string { + return flagNames(f) +} + +// IsRequired returns whether or not the flag is required +func (f *PathFlag) IsRequired() bool { + return f.Required +} + +// TakesValue returns true of the flag takes a value, otherwise false +func (f *PathFlag) TakesValue() bool { + return true +} + +// GetUsage returns the usage string for the flag +func (f *PathFlag) GetUsage() string { + return f.Usage +} + +// GetValue returns the flags value as string representation and an empty +// string if the flag takes no value at all. +func (f *PathFlag) GetValue() string { + return f.Value +} + +// Apply populates the flag given the flag set and environment +func (f *PathFlag) Apply(set *flag.FlagSet) error { + if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { + f.Value = val + f.HasBeenSet = true + } + + for _, name := range f.Names() { + if f.Destination != nil { + set.StringVar(f.Destination, name, f.Value, f.Usage) + continue + } + set.String(name, f.Value, f.Usage) + } + + return nil +} + +// String looks up the value of a local PathFlag, returns +// "" if not found +func (c *Context) Path(name string) string { + if fs := lookupFlagSet(name, c); fs != nil { + return lookupPath(name, fs) + } + + return "" +} + +func lookupPath(name string, set *flag.FlagSet) string { + f := set.Lookup(name) + if f != nil { + parsed, err := f.Value.String(), error(nil) + if err != nil { + return "" + } + return parsed + } + return "" +} diff --git a/vendor/github.com/urfave/cli/flag_string.go b/vendor/github.com/urfave/cli/v2/flag_string.go similarity index 59% rename from vendor/github.com/urfave/cli/flag_string.go rename to vendor/github.com/urfave/cli/v2/flag_string.go index 9f29da40b9..bcd82530cc 100644 --- a/vendor/github.com/urfave/cli/flag_string.go +++ b/vendor/github.com/urfave/cli/v2/flag_string.go @@ -5,67 +5,70 @@ import "flag" // StringFlag is a flag with type string type StringFlag struct { Name string + Aliases []string Usage string - EnvVar string + EnvVars []string FilePath string Required bool Hidden bool TakesFile bool Value string + DefaultText string Destination *string + HasBeenSet bool +} + +// IsSet returns whether or not the flag has been set through env or file +func (f *StringFlag) IsSet() bool { + return f.HasBeenSet } // String returns a readable representation of this value // (for usage defaults) -func (f StringFlag) String() string { +func (f *StringFlag) String() string { return FlagStringer(f) } -// GetName returns the name of the flag -func (f StringFlag) GetName() string { - return f.Name +// Names returns the names of the flag +func (f *StringFlag) Names() []string { + return flagNames(f) } // IsRequired returns whether or not the flag is required -func (f StringFlag) IsRequired() bool { +func (f *StringFlag) IsRequired() bool { return f.Required } // TakesValue returns true of the flag takes a value, otherwise false -func (f StringFlag) TakesValue() bool { +func (f *StringFlag) TakesValue() bool { return true } // GetUsage returns the usage string for the flag -func (f StringFlag) GetUsage() string { +func (f *StringFlag) GetUsage() string { return f.Usage } // GetValue returns the flags value as string representation and an empty // string if the flag takes no value at all. -func (f StringFlag) GetValue() string { +func (f *StringFlag) GetValue() string { return f.Value } // Apply populates the flag given the flag set and environment -// Ignores errors -func (f StringFlag) Apply(set *flag.FlagSet) { - _ = f.ApplyWithError(set) -} - -// ApplyWithError populates the flag given the flag set and environment -func (f StringFlag) ApplyWithError(set *flag.FlagSet) error { - if envVal, ok := flagFromFileEnv(f.FilePath, f.EnvVar); ok { - f.Value = envVal +func (f *StringFlag) Apply(set *flag.FlagSet) error { + if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { + f.Value = val + f.HasBeenSet = true } - eachName(f.Name, func(name string) { + for _, name := range f.Names() { if f.Destination != nil { set.StringVar(f.Destination, name, f.Value, f.Usage) - return + continue } set.String(name, f.Value, f.Usage) - }) + } return nil } @@ -73,13 +76,7 @@ func (f StringFlag) ApplyWithError(set *flag.FlagSet) error { // String looks up the value of a local StringFlag, returns // "" if not found func (c *Context) String(name string) string { - return lookupString(name, c.flagSet) -} - -// GlobalString looks up the value of a global StringFlag, returns -// "" if not found -func (c *Context) GlobalString(name string) string { - if fs := lookupGlobalFlagSet(name, c); fs != nil { + if fs := lookupFlagSet(name, c); fs != nil { return lookupString(name, fs) } return "" diff --git a/vendor/github.com/urfave/cli/v2/flag_string_slice.go b/vendor/github.com/urfave/cli/v2/flag_string_slice.go new file mode 100644 index 0000000000..a114a495eb --- /dev/null +++ b/vendor/github.com/urfave/cli/v2/flag_string_slice.go @@ -0,0 +1,159 @@ +package cli + +import ( + "encoding/json" + "flag" + "fmt" + "strings" +) + +// StringSlice wraps a []string to satisfy flag.Value +type StringSlice struct { + slice []string + hasBeenSet bool +} + +// NewStringSlice creates a *StringSlice with default values +func NewStringSlice(defaults ...string) *StringSlice { + return &StringSlice{slice: append([]string{}, defaults...)} +} + +// Set appends the string value to the list of values +func (s *StringSlice) Set(value string) error { + if !s.hasBeenSet { + s.slice = []string{} + s.hasBeenSet = true + } + + if strings.HasPrefix(value, slPfx) { + // Deserializing assumes overwrite + _ = json.Unmarshal([]byte(strings.Replace(value, slPfx, "", 1)), &s.slice) + s.hasBeenSet = true + return nil + } + + s.slice = append(s.slice, value) + + return nil +} + +// String returns a readable representation of this value (for usage defaults) +func (s *StringSlice) String() string { + return fmt.Sprintf("%s", s.slice) +} + +// Serialize allows StringSlice to fulfill Serializer +func (s *StringSlice) Serialize() string { + jsonBytes, _ := json.Marshal(s.slice) + return fmt.Sprintf("%s%s", slPfx, string(jsonBytes)) +} + +// Value returns the slice of strings set by this flag +func (s *StringSlice) Value() []string { + return s.slice +} + +// Get returns the slice of strings set by this flag +func (s *StringSlice) Get() interface{} { + return *s +} + +// StringSliceFlag is a flag with type *StringSlice +type StringSliceFlag struct { + Name string + Aliases []string + Usage string + EnvVars []string + FilePath string + Required bool + Hidden bool + TakesFile bool + Value *StringSlice + DefaultText string + HasBeenSet bool +} + +// IsSet returns whether or not the flag has been set through env or file +func (f *StringSliceFlag) IsSet() bool { + return f.HasBeenSet +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f *StringSliceFlag) String() string { + return FlagStringer(f) +} + +// Names returns the names of the flag +func (f *StringSliceFlag) Names() []string { + return flagNames(f) +} + +// IsRequired returns whether or not the flag is required +func (f *StringSliceFlag) IsRequired() bool { + return f.Required +} + +// TakesValue returns true of the flag takes a value, otherwise false +func (f *StringSliceFlag) TakesValue() bool { + return true +} + +// GetUsage returns the usage string for the flag +func (f *StringSliceFlag) GetUsage() string { + return f.Usage +} + +// GetValue returns the flags value as string representation and an empty +// string if the flag takes no value at all. +func (f *StringSliceFlag) GetValue() string { + if f.Value != nil { + return f.Value.String() + } + return "" +} + +// Apply populates the flag given the flag set and environment +func (f *StringSliceFlag) Apply(set *flag.FlagSet) error { + if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { + f.Value = &StringSlice{} + + for _, s := range strings.Split(val, ",") { + if err := f.Value.Set(strings.TrimSpace(s)); err != nil { + return fmt.Errorf("could not parse %q as string value for flag %s: %s", val, f.Name, err) + } + } + + f.HasBeenSet = true + } + + for _, name := range f.Names() { + if f.Value == nil { + f.Value = &StringSlice{} + } + set.Var(f.Value, name, f.Usage) + } + + return nil +} + +// StringSlice looks up the value of a local StringSliceFlag, returns +// nil if not found +func (c *Context) StringSlice(name string) []string { + if fs := lookupFlagSet(name, c); fs != nil { + return lookupStringSlice(name, fs) + } + return nil +} + +func lookupStringSlice(name string, set *flag.FlagSet) []string { + f := set.Lookup(name) + if f != nil { + parsed, err := (f.Value.(*StringSlice)).Value(), error(nil) + if err != nil { + return nil + } + return parsed + } + return nil +} diff --git a/vendor/github.com/urfave/cli/flag_uint.go b/vendor/github.com/urfave/cli/v2/flag_uint.go similarity index 56% rename from vendor/github.com/urfave/cli/flag_uint.go rename to vendor/github.com/urfave/cli/v2/flag_uint.go index d6a04f4087..9f592388fe 100644 --- a/vendor/github.com/urfave/cli/flag_uint.go +++ b/vendor/github.com/urfave/cli/v2/flag_uint.go @@ -9,85 +9,84 @@ import ( // UintFlag is a flag with type uint type UintFlag struct { Name string + Aliases []string Usage string - EnvVar string + EnvVars []string FilePath string Required bool Hidden bool Value uint + DefaultText string Destination *uint + HasBeenSet bool +} + +// IsSet returns whether or not the flag has been set through env or file +func (f *UintFlag) IsSet() bool { + return f.HasBeenSet } // String returns a readable representation of this value // (for usage defaults) -func (f UintFlag) String() string { +func (f *UintFlag) String() string { return FlagStringer(f) } -// GetName returns the name of the flag -func (f UintFlag) GetName() string { - return f.Name +// Names returns the names of the flag +func (f *UintFlag) Names() []string { + return flagNames(f) } // IsRequired returns whether or not the flag is required -func (f UintFlag) IsRequired() bool { +func (f *UintFlag) IsRequired() bool { return f.Required } // TakesValue returns true of the flag takes a value, otherwise false -func (f UintFlag) TakesValue() bool { +func (f *UintFlag) TakesValue() bool { return true } // GetUsage returns the usage string for the flag -func (f UintFlag) GetUsage() string { +func (f *UintFlag) GetUsage() string { return f.Usage } // Apply populates the flag given the flag set and environment -// Ignores errors -func (f UintFlag) Apply(set *flag.FlagSet) { - _ = f.ApplyWithError(set) -} - -// ApplyWithError populates the flag given the flag set and environment -func (f UintFlag) ApplyWithError(set *flag.FlagSet) error { - if envVal, ok := flagFromFileEnv(f.FilePath, f.EnvVar); ok { - envValInt, err := strconv.ParseUint(envVal, 0, 64) - if err != nil { - return fmt.Errorf("could not parse %s as uint value for flag %s: %s", envVal, f.Name, err) +func (f *UintFlag) Apply(set *flag.FlagSet) error { + if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { + if val != "" { + valInt, err := strconv.ParseUint(val, 0, 64) + if err != nil { + return fmt.Errorf("could not parse %q as uint value for flag %s: %s", val, f.Name, err) + } + + f.Value = uint(valInt) + f.HasBeenSet = true } - - f.Value = uint(envValInt) } - eachName(f.Name, func(name string) { + for _, name := range f.Names() { if f.Destination != nil { set.UintVar(f.Destination, name, f.Value, f.Usage) - return + continue } set.Uint(name, f.Value, f.Usage) - }) + } return nil } // GetValue returns the flags value as string representation and an empty // string if the flag takes no value at all. -func (f UintFlag) GetValue() string { +func (f *UintFlag) GetValue() string { return fmt.Sprintf("%d", f.Value) } // Uint looks up the value of a local UintFlag, returns // 0 if not found func (c *Context) Uint(name string) uint { - return lookupUint(name, c.flagSet) -} - -// GlobalUint looks up the value of a global UintFlag, returns -// 0 if not found -func (c *Context) GlobalUint(name string) uint { - if fs := lookupGlobalFlagSet(name, c); fs != nil { + if fs := lookupFlagSet(name, c); fs != nil { return lookupUint(name, fs) } return 0 diff --git a/vendor/github.com/urfave/cli/flag_uint64.go b/vendor/github.com/urfave/cli/v2/flag_uint64.go similarity index 56% rename from vendor/github.com/urfave/cli/flag_uint64.go rename to vendor/github.com/urfave/cli/v2/flag_uint64.go index ea6493a8be..5bbd1fa4b9 100644 --- a/vendor/github.com/urfave/cli/flag_uint64.go +++ b/vendor/github.com/urfave/cli/v2/flag_uint64.go @@ -9,85 +9,84 @@ import ( // Uint64Flag is a flag with type uint64 type Uint64Flag struct { Name string + Aliases []string Usage string - EnvVar string + EnvVars []string FilePath string Required bool Hidden bool Value uint64 + DefaultText string Destination *uint64 + HasBeenSet bool +} + +// IsSet returns whether or not the flag has been set through env or file +func (f *Uint64Flag) IsSet() bool { + return f.HasBeenSet } // String returns a readable representation of this value // (for usage defaults) -func (f Uint64Flag) String() string { +func (f *Uint64Flag) String() string { return FlagStringer(f) } -// GetName returns the name of the flag -func (f Uint64Flag) GetName() string { - return f.Name +// Names returns the names of the flag +func (f *Uint64Flag) Names() []string { + return flagNames(f) } // IsRequired returns whether or not the flag is required -func (f Uint64Flag) IsRequired() bool { +func (f *Uint64Flag) IsRequired() bool { return f.Required } // TakesValue returns true of the flag takes a value, otherwise false -func (f Uint64Flag) TakesValue() bool { +func (f *Uint64Flag) TakesValue() bool { return true } // GetUsage returns the usage string for the flag -func (f Uint64Flag) GetUsage() string { +func (f *Uint64Flag) GetUsage() string { return f.Usage } -// GetValue returns the flags value as string representation and an empty -// string if the flag takes no value at all. -func (f Uint64Flag) GetValue() string { - return fmt.Sprintf("%d", f.Value) -} - // Apply populates the flag given the flag set and environment -// Ignores errors -func (f Uint64Flag) Apply(set *flag.FlagSet) { - _ = f.ApplyWithError(set) -} - -// ApplyWithError populates the flag given the flag set and environment -func (f Uint64Flag) ApplyWithError(set *flag.FlagSet) error { - if envVal, ok := flagFromFileEnv(f.FilePath, f.EnvVar); ok { - envValInt, err := strconv.ParseUint(envVal, 0, 64) - if err != nil { - return fmt.Errorf("could not parse %s as uint64 value for flag %s: %s", envVal, f.Name, err) +func (f *Uint64Flag) Apply(set *flag.FlagSet) error { + if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { + if val != "" { + valInt, err := strconv.ParseUint(val, 0, 64) + if err != nil { + return fmt.Errorf("could not parse %q as uint64 value for flag %s: %s", val, f.Name, err) + } + + f.Value = valInt + f.HasBeenSet = true } - - f.Value = envValInt } - eachName(f.Name, func(name string) { + for _, name := range f.Names() { if f.Destination != nil { set.Uint64Var(f.Destination, name, f.Value, f.Usage) - return + continue } set.Uint64(name, f.Value, f.Usage) - }) + } return nil } -// Uint64 looks up the value of a local Uint64Flag, returns -// 0 if not found -func (c *Context) Uint64(name string) uint64 { - return lookupUint64(name, c.flagSet) +// GetValue returns the flags value as string representation and an empty +// string if the flag takes no value at all. +func (f *Uint64Flag) GetValue() string { + return fmt.Sprintf("%d", f.Value) } -// GlobalUint64 looks up the value of a global Uint64Flag, returns +// Uint64 looks up the value of a local Uint64Flag, returns // 0 if not found -func (c *Context) GlobalUint64(name string) uint64 { - if fs := lookupGlobalFlagSet(name, c); fs != nil { +func (c *Context) Uint64(name string) uint64 { + if fs := lookupFlagSet(name, c); fs != nil { return lookupUint64(name, fs) } return 0 diff --git a/vendor/github.com/urfave/cli/funcs.go b/vendor/github.com/urfave/cli/v2/funcs.go similarity index 88% rename from vendor/github.com/urfave/cli/funcs.go rename to vendor/github.com/urfave/cli/v2/funcs.go index 0036b1130a..474c48faf9 100644 --- a/vendor/github.com/urfave/cli/funcs.go +++ b/vendor/github.com/urfave/cli/v2/funcs.go @@ -1,6 +1,6 @@ package cli -// BashCompleteFunc is an action to execute when the bash-completion flag is set +// BashCompleteFunc is an action to execute when the shell completion flag is set type BashCompleteFunc func(*Context) // BeforeFunc is an action to execute before any subcommands are run, but after @@ -23,7 +23,7 @@ type CommandNotFoundFunc func(*Context, string) // is displayed and the execution is interrupted. type OnUsageErrorFunc func(context *Context, err error, isSubcommand bool) error -// ExitErrHandlerFunc is executed if provided in order to handle ExitError values +// ExitErrHandlerFunc is executed if provided in order to handle exitError values // returned by Actions and Before/After functions. type ExitErrHandlerFunc func(context *Context, err error) @@ -33,11 +33,11 @@ type FlagStringFunc func(Flag) string // FlagNamePrefixFunc is used by the default FlagStringFunc to create prefix // text for a flag's full name. -type FlagNamePrefixFunc func(fullName, placeholder string) string +type FlagNamePrefixFunc func(fullName []string, placeholder string) string // FlagEnvHintFunc is used by the default FlagStringFunc to annotate flag help // with the environment variable details. -type FlagEnvHintFunc func(envVar, str string) string +type FlagEnvHintFunc func(envVars []string, str string) string // FlagFileHintFunc is used by the default FlagStringFunc to annotate flag help // with the file path details. diff --git a/vendor/github.com/urfave/cli/go.mod b/vendor/github.com/urfave/cli/v2/go.mod similarity index 82% rename from vendor/github.com/urfave/cli/go.mod rename to vendor/github.com/urfave/cli/v2/go.mod index 7d04d20167..c38d41c14b 100644 --- a/vendor/github.com/urfave/cli/go.mod +++ b/vendor/github.com/urfave/cli/v2/go.mod @@ -1,4 +1,4 @@ -module github.com/urfave/cli +module github.com/urfave/cli/v2 go 1.11 diff --git a/vendor/github.com/urfave/cli/go.sum b/vendor/github.com/urfave/cli/v2/go.sum similarity index 100% rename from vendor/github.com/urfave/cli/go.sum rename to vendor/github.com/urfave/cli/v2/go.sum diff --git a/vendor/github.com/urfave/cli/help.go b/vendor/github.com/urfave/cli/v2/help.go similarity index 91% rename from vendor/github.com/urfave/cli/help.go rename to vendor/github.com/urfave/cli/v2/help.go index 2280e338ef..aa5947d6e9 100644 --- a/vendor/github.com/urfave/cli/help.go +++ b/vendor/github.com/urfave/cli/v2/help.go @@ -10,7 +10,7 @@ import ( "unicode/utf8" ) -var helpCommand = Command{ +var helpCommand = &Command{ Name: "help", Aliases: []string{"h"}, Usage: "Shows a list of commands or help for one command", @@ -26,7 +26,7 @@ var helpCommand = Command{ }, } -var helpSubcommand = Command{ +var helpSubcommand = &Command{ Name: "help", Aliases: []string{"h"}, Usage: "Shows a list of commands or help for one command", @@ -97,7 +97,7 @@ func DefaultAppComplete(c *Context) { DefaultCompleteWithFlags(nil)(c) } -func printCommandSuggestions(commands []Command, writer io.Writer) { +func printCommandSuggestions(commands []*Command, writer io.Writer) { for _, command := range commands { if command.Hidden { continue @@ -135,10 +135,10 @@ func printFlagSuggestions(lastArg string, flags []Flag, writer io.Writer) { cur := strings.TrimPrefix(lastArg, "-") cur = strings.TrimPrefix(cur, "-") for _, flag := range flags { - if bflag, ok := flag.(BoolFlag); ok && bflag.Hidden { + if bflag, ok := flag.(*BoolFlag); ok && bflag.Hidden { continue } - for _, name := range strings.Split(flag.GetName(), ",") { + for _, name := range flag.Names(){ name = strings.TrimSpace(name) // this will get total count utf8 letters in flag name count := utf8.RuneCountInString(name) @@ -151,7 +151,7 @@ func printFlagSuggestions(lastArg string, flags []Flag, writer io.Writer) { continue } // match if last argument matches this flag and it is not repeated - if strings.HasPrefix(name, cur) && cur != name && !cliArgContains(flag.GetName()) { + if strings.HasPrefix(name, cur) && cur != name && !cliArgContains(name) { flagCompletion := fmt.Sprintf("%s%s", strings.Repeat("-", count), name) _, _ = fmt.Fprintln(writer, flagCompletion) } @@ -207,7 +207,7 @@ func ShowCommandHelp(ctx *Context, command string) error { } if ctx.App.CommandNotFound == nil { - return NewExitError(fmt.Sprintf("No help topic for '%v'", command), 3) + return Exit(fmt.Sprintf("No help topic for '%v'", command), 3) } ctx.App.CommandNotFound(ctx, command) @@ -216,7 +216,15 @@ func ShowCommandHelp(ctx *Context, command string) error { // ShowSubcommandHelp prints help for the given subcommand func ShowSubcommandHelp(c *Context) error { - return ShowCommandHelp(c, c.Command.Name) + if c == nil { + return nil + } + + if c.Command != nil { + return ShowCommandHelp(c, c.Command.Name) + } + + return ShowCommandHelp(c, "") } // ShowVersion prints the version number of the App @@ -263,6 +271,7 @@ func printHelpCustom(out io.Writer, templ string, data interface{}, customFuncs w := tabwriter.NewWriter(out, 1, 8, 2, ' ', 0) t := template.Must(template.New("help").Funcs(funcMap).Parse(templ)) + err := t.Execute(w, data) if err != nil { // If the writer is closed, t.Execute will fail, and there's nothing @@ -281,24 +290,20 @@ func printHelp(out io.Writer, templ string, data interface{}) { func checkVersion(c *Context) bool { found := false - if VersionFlag.GetName() != "" { - eachName(VersionFlag.GetName(), func(name string) { - if c.GlobalBool(name) || c.Bool(name) { - found = true - } - }) + for _, name := range VersionFlag.Names() { + if c.Bool(name) { + found = true + } } return found } func checkHelp(c *Context) bool { found := false - if HelpFlag.GetName() != "" { - eachName(HelpFlag.GetName(), func(name string) { - if c.GlobalBool(name) || c.Bool(name) { - found = true - } - }) + for _, name := range HelpFlag.Names() { + if c.Bool(name) { + found = true + } } return found } @@ -329,7 +334,7 @@ func checkShellCompleteFlag(a *App, arguments []string) (bool, []string) { pos := len(arguments) - 1 lastArg := arguments[pos] - if lastArg != "--"+BashCompletionFlag.GetName() { + if lastArg != "--generate-bash-completion" { return false, arguments } diff --git a/vendor/github.com/urfave/cli/parse.go b/vendor/github.com/urfave/cli/v2/parse.go similarity index 100% rename from vendor/github.com/urfave/cli/parse.go rename to vendor/github.com/urfave/cli/v2/parse.go diff --git a/vendor/github.com/urfave/cli/sort.go b/vendor/github.com/urfave/cli/v2/sort.go similarity index 100% rename from vendor/github.com/urfave/cli/sort.go rename to vendor/github.com/urfave/cli/v2/sort.go diff --git a/vendor/github.com/urfave/cli/template.go b/vendor/github.com/urfave/cli/v2/template.go similarity index 98% rename from vendor/github.com/urfave/cli/template.go rename to vendor/github.com/urfave/cli/v2/template.go index c631fb97dd..78e182f5c4 100644 --- a/vendor/github.com/urfave/cli/template.go +++ b/vendor/github.com/urfave/cli/v2/template.go @@ -20,7 +20,6 @@ AUTHOR{{with $length := len .Authors}}{{if ne 1 $length}}S{{end}}{{end}}: {{end}}{{$author}}{{end}}{{end}}{{if .VisibleCommands}} COMMANDS:{{range .VisibleCategories}}{{if .Name}} - {{.Name}}:{{range .VisibleCommands}} {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{range .VisibleCommands}} {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}{{end}}{{if .VisibleFlags}} @@ -63,7 +62,6 @@ USAGE: {{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} command{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}} COMMANDS:{{range .VisibleCategories}}{{if .Name}} - {{.Name}}:{{range .VisibleCommands}} {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{range .VisibleCommands}} {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}{{if .VisibleFlags}} @@ -74,8 +72,9 @@ OPTIONS: ` var MarkdownDocTemplate = `% {{ .App.Name }}(8) {{ .App.Description }} - -% {{ .App.Author }} +{{ range $Author := .App.Authors}} +% {{ $Author.Name }} +{{- end}} # NAME diff --git a/vendor/modules.txt b/vendor/modules.txt index 3dae248bd4..fa17e855d2 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -116,8 +116,8 @@ github.com/shurcooL/sanitized_anchor_name github.com/sirupsen/logrus # github.com/spf13/pflag v1.0.5 github.com/spf13/pflag -# github.com/urfave/cli v1.22.2 -github.com/urfave/cli +# github.com/urfave/cli/v2 v2.0.0 +github.com/urfave/cli/v2 # golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586 golang.org/x/crypto/ssh/terminal # golang.org/x/net v0.0.0-20191204025024-5ee1b9f4859a