From 0d357a9f609350c5acad55ad66fd8f596e69a767 Mon Sep 17 00:00:00 2001 From: Mritunjay Kumar Sharma Date: Mon, 27 Dec 2021 01:49:39 +0530 Subject: [PATCH] migrate from urfave/cli/v1 to urfave/cli/v2 (#263) Signed-off-by: Mritunjay Sharma --- go.mod | 2 +- go.sum | 6 +- pkg/app/master/cli.go | 14 +- pkg/app/master/commands/build/cli.go | 16 +- pkg/app/master/commands/build/flags.go | 479 +++++----- pkg/app/master/commands/cliflags.go | 894 +++++++++--------- pkg/app/master/commands/clifvgetter.go | 22 +- pkg/app/master/commands/cliprompt.go | 2 +- pkg/app/master/commands/common.go | 4 +- pkg/app/master/commands/containerize/cli.go | 6 +- pkg/app/master/commands/convert/cli.go | 6 +- pkg/app/master/commands/debug/cli.go | 6 +- pkg/app/master/commands/dockerclipm/cli.go | 4 +- pkg/app/master/commands/edit/cli.go | 6 +- pkg/app/master/commands/help/cli.go | 4 +- pkg/app/master/commands/install/cli.go | 20 +- pkg/app/master/commands/lint/cli.go | 6 +- pkg/app/master/commands/lint/flags.go | 133 +-- pkg/app/master/commands/probe/cli.go | 6 +- pkg/app/master/commands/profile/cli.go | 14 +- pkg/app/master/commands/run/cli.go | 6 +- pkg/app/master/commands/run/flags.go | 44 +- pkg/app/master/commands/server/cli.go | 4 +- pkg/app/master/commands/update/cli.go | 29 +- pkg/app/master/commands/version/cli.go | 8 +- pkg/app/master/commands/xray/cli.go | 6 +- pkg/app/master/commands/xray/flags.go | 267 +++--- vendor/github.com/urfave/cli/.gitignore | 4 - vendor/github.com/urfave/cli/appveyor.yml | 28 - vendor/github.com/urfave/cli/category.go | 44 - vendor/github.com/urfave/cli/context.go | 347 ------- vendor/github.com/urfave/cli/errors.go | 115 --- vendor/github.com/urfave/cli/flag_bool_t.go | 110 --- .../github.com/urfave/cli/flag_int64_slice.go | 197 ---- .../github.com/urfave/cli/flag_int_slice.go | 196 ---- .../urfave/cli/flag_string_slice.go | 182 ---- vendor/github.com/urfave/cli/{ => v2}/.flake8 | 0 vendor/github.com/urfave/cli/v2/.gitignore | 7 + .../urfave/cli/{ => v2}/CODE_OF_CONDUCT.md | 0 vendor/github.com/urfave/cli/{ => v2}/LICENSE | 0 .../github.com/urfave/cli/{ => v2}/README.md | 54 +- vendor/github.com/urfave/cli/{ => v2}/app.go | 201 ++-- vendor/github.com/urfave/cli/v2/args.go | 54 ++ vendor/github.com/urfave/cli/v2/category.go | 79 ++ vendor/github.com/urfave/cli/{ => v2}/cli.go | 17 +- .../github.com/urfave/cli/{ => v2}/command.go | 205 ++-- vendor/github.com/urfave/cli/v2/context.go | 273 ++++++ vendor/github.com/urfave/cli/{ => v2}/docs.go | 14 +- vendor/github.com/urfave/cli/v2/errors.go | 141 +++ vendor/github.com/urfave/cli/{ => v2}/fish.go | 18 +- 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 | 163 ++++ .../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 | 159 ++++ .../urfave/cli/v2/flag_int_slice.go | 173 ++++ vendor/github.com/urfave/cli/v2/flag_path.go | 95 ++ .../urfave/cli/{ => v2}/flag_string.go | 53 +- .../urfave/cli/v2/flag_string_slice.go | 180 ++++ .../urfave/cli/v2/flag_timestamp.go | 154 +++ .../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 | 4 +- vendor/github.com/urfave/cli/{ => v2}/go.sum | 4 +- vendor/github.com/urfave/cli/{ => v2}/help.go | 77 +- .../github.com/urfave/cli/{ => v2}/parse.go | 0 vendor/github.com/urfave/cli/{ => v2}/sort.go | 0 .../urfave/cli/{ => v2}/template.go | 17 +- vendor/modules.txt | 4 +- 74 files changed, 3227 insertions(+), 2972 deletions(-) delete mode 100644 vendor/github.com/urfave/cli/.gitignore delete mode 100644 vendor/github.com/urfave/cli/appveyor.yml 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/errors.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%) create mode 100644 vendor/github.com/urfave/cli/v2/.gitignore 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 (53%) rename vendor/github.com/urfave/cli/{ => v2}/app.go (77%) 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 (56%) create mode 100644 vendor/github.com/urfave/cli/v2/context.go rename vendor/github.com/urfave/cli/{ => v2}/docs.go (91%) create mode 100644 vendor/github.com/urfave/cli/v2/errors.go rename vendor/github.com/urfave/cli/{ => v2}/fish.go (92%) rename vendor/github.com/urfave/cli/{ => v2}/flag.go (53%) 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 create mode 100644 vendor/github.com/urfave/cli/v2/flag_timestamp.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 (68%) rename vendor/github.com/urfave/cli/{ => v2}/go.sum (89%) rename vendor/github.com/urfave/cli/{ => v2}/help.go (85%) 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 (91%) diff --git a/go.mod b/go.mod index dacc46942b..4411265a29 100644 --- a/go.mod +++ b/go.mod @@ -43,7 +43,7 @@ require ( github.com/sirupsen/logrus v1.8.1 github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 github.com/ulikunitz/xz v0.5.7 // indirect - github.com/urfave/cli v1.22.4 + github.com/urfave/cli/v2 v2.3.0 go.opencensus.io v0.23.0 // indirect golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 golang.org/x/sys v0.0.0-20210921065528-437939a70204 diff --git a/go.sum b/go.sum index bc8705575b..787a12af8a 100644 --- a/go.sum +++ b/go.sum @@ -687,9 +687,10 @@ github.com/ulyssessouza/godotenv v1.3.1-0.20210806120901-e417b721114e/go.mod h1: github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= +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 v1.22.4 h1:u7tSpNPPswAFymm8IehJhy4uJMlUuU/GmqSkvJ1InXA= -github.com/urfave/cli v1.22.4/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= +github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M= +github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= github.com/vishvananda/netlink v0.0.0-20181108222139-023a6dafdcdf/go.mod h1:+SR5DhBJrl6ZM7CoCKvpw5BKroDKQ+PJqOg65H/2ktk= github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE= github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho= @@ -1034,6 +1035,7 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWD gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/pkg/app/master/cli.go b/pkg/app/master/cli.go index 86899c1061..7e54427030 100644 --- a/pkg/app/master/cli.go +++ b/pkg/app/master/cli.go @@ -27,7 +27,7 @@ import ( v "github.com/docker-slim/docker-slim/pkg/version" log "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // DockerSlim app CLI constants @@ -73,18 +73,18 @@ func newCLI() *cli.App { cliApp.Flags = commands.GlobalFlags() cliApp.Before = func(ctx *cli.Context) error { - if ctx.GlobalBool(commands.FlagNoColor) { + if ctx.Bool(commands.FlagNoColor) { app.NoColor() } - if ctx.GlobalBool(commands.FlagDebug) { + if ctx.Bool(commands.FlagDebug) { log.SetLevel(log.DebugLevel) } else { - if ctx.GlobalBool(commands.FlagVerbose) { + if ctx.Bool(commands.FlagVerbose) { log.SetLevel(log.InfoLevel) } else { logLevel := log.WarnLevel - logLevelName := ctx.GlobalString(commands.FlagLogLevel) + logLevelName := ctx.String(commands.FlagLogLevel) switch logLevelName { case "trace": logLevel = log.TraceLevel @@ -108,7 +108,7 @@ func newCLI() *cli.App { } } - if path := ctx.GlobalString(commands.FlagLog); path != "" { + if path := ctx.String(commands.FlagLog); path != "" { f, err := os.Create(path) if err != nil { return err @@ -116,7 +116,7 @@ func newCLI() *cli.App { log.SetOutput(f) } - logFormat := ctx.GlobalString(commands.FlagLogFormat) + logFormat := ctx.String(commands.FlagLogFormat) switch logFormat { case "text": log.SetFormatter(&log.TextFormatter{DisableColors: true}) diff --git a/pkg/app/master/commands/build/cli.go b/pkg/app/master/commands/build/cli.go index b9e4f157d8..f3c783defc 100644 --- a/pkg/app/master/commands/build/cli.go +++ b/pkg/app/master/commands/build/cli.go @@ -10,7 +10,7 @@ import ( "github.com/docker-slim/docker-slim/pkg/app/master/config" "github.com/docker-slim/docker-slim/pkg/util/errutil" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) const ( @@ -19,7 +19,7 @@ const ( Alias = "b" ) -var CLI = cli.Command{ +var CLI = &cli.Command{ Name: Name, Aliases: []string{Alias}, Usage: Usage, @@ -198,7 +198,7 @@ var CLI = cli.Command{ targetRef = ctx.String(commands.FlagTarget) if targetRef == "" { - if len(ctx.Args()) < 1 { + if ctx.Args().Len() < 1 { xc.Out.Error("param.target", "missing image ID/name") cli.ShowCommandHelp(ctx, Name) return nil @@ -209,7 +209,7 @@ var CLI = cli.Command{ } else { targetRef = cbOpts.DockerfileContext if targetRef == "" { - if len(ctx.Args()) < 1 { + if ctx.Args().Len() < 1 { xc.Out.Error("param.target", "missing Dockerfile build context directory") cli.ShowCommandHelp(ctx, Name) return nil @@ -502,7 +502,7 @@ var CLI = cli.Command{ doKeepTmpArtifacts := ctx.Bool(FlagKeepTmpArtifacts) - doExcludeMounts := ctx.BoolT(commands.FlagExcludeMounts) + doExcludeMounts := ctx.Bool(commands.FlagExcludeMounts) if doExcludeMounts { for mpath := range volumeMounts { excludePatterns[mpath] = nil @@ -603,7 +603,7 @@ var CLI = cli.Command{ }) } - commandReport := ctx.GlobalString(commands.FlagCommandReport) + commandReport := ctx.String(commands.FlagCommandReport) if commandReport == "off" { commandReport = "" } @@ -684,8 +684,8 @@ var CLI = cli.Command{ execCmd, string(execFileCmd), deleteFatImage, - ctx.GlobalString(commands.FlagLogLevel), - ctx.GlobalString(commands.FlagLogFormat)) + ctx.String(commands.FlagLogLevel), + ctx.String(commands.FlagLogFormat)) return nil }, diff --git a/pkg/app/master/commands/build/flags.go b/pkg/app/master/commands/build/flags.go index 2393d06092..83b445be57 100644 --- a/pkg/app/master/commands/build/flags.go +++ b/pkg/app/master/commands/build/flags.go @@ -9,7 +9,7 @@ import ( "github.com/docker-slim/docker-slim/pkg/app/master/config" log "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // Build command flag names @@ -128,250 +128,251 @@ const ( ) var Flags = map[string]cli.Flag{ - FlagShowBuildLogs: cli.BoolFlag{ - Name: FlagShowBuildLogs, - Usage: FlagShowBuildLogsUsage, - EnvVar: "DSLIM_SHOW_BLOGS", - }, - FlagPathPerms: cli.StringSliceFlag{ - Name: FlagPathPerms, - Value: &cli.StringSlice{}, - Usage: FlagPathPermsUsage, - EnvVar: "DSLIM_PATH_PERMS", - }, - FlagPathPermsFile: cli.StringFlag{ - Name: FlagPathPermsFile, - Value: "", - Usage: FlagPathPermsFileUsage, - EnvVar: "DSLIM_PATH_PERMS_FILE", - }, - FlagPreservePath: cli.StringSliceFlag{ - Name: FlagPreservePath, - Value: &cli.StringSlice{}, - Usage: FlagPreservePathUsage, - EnvVar: "DSLIM_PRESERVE_PATH", - }, - FlagPreservePathFile: cli.StringFlag{ - Name: FlagPreservePathFile, - Value: "", - Usage: FlagPreservePathFileUsage, - EnvVar: "DSLIM_PRESERVE_PATH_FILE", - }, - FlagIncludePath: cli.StringSliceFlag{ - Name: FlagIncludePath, - Value: &cli.StringSlice{}, - Usage: FlagIncludePathUsage, - EnvVar: "DSLIM_INCLUDE_PATH", - }, - FlagIncludePathFile: cli.StringFlag{ - Name: FlagIncludePathFile, - Value: "", - Usage: FlagIncludePathFileUsage, - EnvVar: "DSLIM_INCLUDE_PATH_FILE", - }, - FlagIncludeBin: cli.StringSliceFlag{ - Name: FlagIncludeBin, - Value: &cli.StringSlice{}, - Usage: FlagIncludeBinUsage, - EnvVar: "DSLIM_INCLUDE_BIN", - }, - FlagIncludeExe: cli.StringSliceFlag{ - Name: FlagIncludeExe, - Value: &cli.StringSlice{}, - Usage: FlagIncludeExeUsage, - EnvVar: "DSLIM_INCLUDE_EXE", - }, - FlagIncludeShell: cli.BoolFlag{ - Name: FlagIncludeShell, - Usage: FlagIncludeShellUsage, - EnvVar: "DSLIM_INCLUDE_SHELL", + FlagShowBuildLogs: &cli.BoolFlag{ + Name: FlagShowBuildLogs, + Usage: FlagShowBuildLogsUsage, + EnvVars: []string{"DSLIM_SHOW_BLOGS"}, + }, + FlagPathPerms: &cli.StringSliceFlag{ + Name: FlagPathPerms, + Value: cli.NewStringSlice(), + Usage: FlagPathPermsUsage, + EnvVars: []string{"DSLIM_PATH_PERMS"}, + }, + FlagPathPermsFile: &cli.StringFlag{ + Name: FlagPathPermsFile, + Value: "", + Usage: FlagPathPermsFileUsage, + EnvVars: []string{"DSLIM_PATH_PERMS_FILE"}, + }, + FlagPreservePath: &cli.StringSliceFlag{ + Name: FlagPreservePath, + Value: cli.NewStringSlice(), + Usage: FlagPreservePathUsage, + EnvVars: []string{"DSLIM_PRESERVE_PATH"}, + }, + FlagPreservePathFile: &cli.StringFlag{ + Name: FlagPreservePathFile, + Value: "", + Usage: FlagPreservePathFileUsage, + EnvVars: []string{"DSLIM_PRESERVE_PATH_FILE"}, + }, + FlagIncludePath: &cli.StringSliceFlag{ + Name: FlagIncludePath, + Value: cli.NewStringSlice(), + Usage: FlagIncludePathUsage, + EnvVars: []string{"DSLIM_INCLUDE_PATH"}, + }, + FlagIncludePathFile: &cli.StringFlag{ + Name: FlagIncludePathFile, + Value: "", + Usage: FlagIncludePathFileUsage, + EnvVars: []string{"DSLIM_INCLUDE_PATH_FILE"}, + }, + FlagIncludeBin: &cli.StringSliceFlag{ + Name: FlagIncludeBin, + Value: cli.NewStringSlice(), + Usage: FlagIncludeBinUsage, + EnvVars: []string{"DSLIM_INCLUDE_BIN"}, + }, + FlagIncludeExe: &cli.StringSliceFlag{ + Name: FlagIncludeExe, + Value: cli.NewStringSlice(), + Usage: FlagIncludeExeUsage, + EnvVars: []string{"DSLIM_INCLUDE_EXE"}, + }, + FlagIncludeShell: &cli.BoolFlag{ + Name: FlagIncludeShell, + Usage: FlagIncludeShellUsage, + EnvVars: []string{"DSLIM_INCLUDE_SHELL"}, }, //// - FlagIncludeCertAll: cli.BoolFlag{ - Name: FlagIncludeCertAll, - Usage: FlagIncludeCertAllUsage, - EnvVar: "DSLIM_INCLUDE_CERT_ALL", - }, - FlagIncludeCertBundles: cli.BoolFlag{ - Name: FlagIncludeCertBundles, - Usage: FlagIncludeCertBundlesUsage, - EnvVar: "DSLIM_INCLUDE_CERT_BUNDLES", - }, - FlagIncludeCertDirs: cli.BoolFlag{ - Name: FlagIncludeCertDirs, - Usage: FlagIncludeCertDirsUsage, - EnvVar: "DSLIM_INCLUDE_CERT_DIRS", - }, - FlagIncludeCertPKAll: cli.BoolFlag{ - Name: FlagIncludeCertPKAll, - Usage: FlagIncludeCertPKAllUsage, - EnvVar: "DSLIM_INCLUDE_CERT_PK_ALL", - }, - FlagIncludeCertPKDirs: cli.BoolFlag{ - Name: FlagIncludeCertPKDirs, - Usage: FlagIncludeCertPKDirsUsage, - EnvVar: "DSLIM_INCLUDE_CERT_PK_DIRS", + FlagIncludeCertAll: &cli.BoolFlag{ + Name: FlagIncludeCertAll, + Usage: FlagIncludeCertAllUsage, + EnvVars: []string{"DSLIM_INCLUDE_CERT_ALL"}, + }, + FlagIncludeCertBundles: &cli.BoolFlag{ + Name: FlagIncludeCertBundles, + Usage: FlagIncludeCertBundlesUsage, + EnvVars: []string{"DSLIM_INCLUDE_CERT_BUNDLES"}, + }, + FlagIncludeCertDirs: &cli.BoolFlag{ + Name: FlagIncludeCertDirs, + Usage: FlagIncludeCertDirsUsage, + EnvVars: []string{"DSLIM_INCLUDE_CERT_DIRS"}, + }, + FlagIncludeCertPKAll: &cli.BoolFlag{ + Name: FlagIncludeCertPKAll, + Usage: FlagIncludeCertPKAllUsage, + EnvVars: []string{"DSLIM_INCLUDE_CERT_PK_ALL"}, + }, + FlagIncludeCertPKDirs: &cli.BoolFlag{ + Name: FlagIncludeCertPKDirs, + Usage: FlagIncludeCertPKDirsUsage, + EnvVars: []string{"DSLIM_INCLUDE_CERT_PK_DIRS"}, }, //// - FlagKeepTmpArtifacts: cli.BoolFlag{ - Name: FlagKeepTmpArtifacts, - Usage: FlagKeepTmpArtifactsUsage, - EnvVar: "DSLIM_KEEP_TMP_ARTIFACTS", - }, - FlagKeepPerms: cli.BoolTFlag{ - Name: FlagKeepPerms, - Usage: FlagKeepPermsUsage, - EnvVar: "DSLIM_KEEP_PERMS", - }, - FlagNewEntrypoint: cli.StringFlag{ - Name: FlagNewEntrypoint, - Value: "", - Usage: FlagNewEntrypointUsage, - EnvVar: "DSLIM_NEW_ENTRYPOINT", - }, - FlagNewCmd: cli.StringFlag{ - Name: FlagNewCmd, - Value: "", - Usage: FlagNewCmdUsage, - EnvVar: "DSLIM_NEW_CMD", - }, - FlagNewExpose: cli.StringSliceFlag{ - Name: FlagNewExpose, - Value: &cli.StringSlice{}, - Usage: FlagNewExposeUsage, - EnvVar: "DSLIM_NEW_EXPOSE", - }, - FlagNewWorkdir: cli.StringFlag{ - Name: FlagNewWorkdir, - Value: "", - Usage: FlagNewWorkdirUsage, - EnvVar: "DSLIM_NEW_WORKDIR", - }, - FlagNewEnv: cli.StringSliceFlag{ - Name: FlagNewEnv, - Value: &cli.StringSlice{}, - Usage: FlagNewEnvUsage, - EnvVar: "DSLIM_NEW_ENV", - }, - FlagNewVolume: cli.StringSliceFlag{ - Name: FlagNewVolume, - Value: &cli.StringSlice{}, - Usage: FlagNewVolumeUsage, - EnvVar: "DSLIM_NEW_VOLUME", - }, - FlagNewLabel: cli.StringSliceFlag{ - Name: FlagNewLabel, - Value: &cli.StringSlice{}, - Usage: FlagNewLabelUsage, - EnvVar: "DSLIM_NEW_LABEL", - }, - FlagTag: cli.StringSliceFlag{ - Name: FlagTag, - Value: &cli.StringSlice{}, - Usage: FlagTagUsage, - EnvVar: "DSLIM_TARGET_TAG", - }, - FlagImageOverrides: cli.StringFlag{ - Name: FlagImageOverrides, - Value: "", - Usage: FlagImageOverridesUsage, - EnvVar: "DSLIM_TARGET_OVERRIDES", + FlagKeepTmpArtifacts: &cli.BoolFlag{ + Name: FlagKeepTmpArtifacts, + Usage: FlagKeepTmpArtifactsUsage, + EnvVars: []string{"DSLIM_KEEP_TMP_ARTIFACTS"}, + }, + FlagKeepPerms: &cli.BoolFlag{ + Name: FlagKeepPerms, + Value: true, + Usage: FlagKeepPermsUsage, + EnvVars: []string{"DSLIM_KEEP_PERMS"}, + }, + FlagNewEntrypoint: &cli.StringFlag{ + Name: FlagNewEntrypoint, + Value: "", + Usage: FlagNewEntrypointUsage, + EnvVars: []string{"DSLIM_NEW_ENTRYPOINT"}, + }, + FlagNewCmd: &cli.StringFlag{ + Name: FlagNewCmd, + Value: "", + Usage: FlagNewCmdUsage, + EnvVars: []string{"DSLIM_NEW_CMD"}, + }, + FlagNewExpose: &cli.StringSliceFlag{ + Name: FlagNewExpose, + Value: cli.NewStringSlice(), + Usage: FlagNewExposeUsage, + EnvVars: []string{"DSLIM_NEW_EXPOSE"}, + }, + FlagNewWorkdir: &cli.StringFlag{ + Name: FlagNewWorkdir, + Value: "", + Usage: FlagNewWorkdirUsage, + EnvVars: []string{"DSLIM_NEW_WORKDIR"}, + }, + FlagNewEnv: &cli.StringSliceFlag{ + Name: FlagNewEnv, + Value: cli.NewStringSlice(), + Usage: FlagNewEnvUsage, + EnvVars: []string{"DSLIM_NEW_ENV"}, + }, + FlagNewVolume: &cli.StringSliceFlag{ + Name: FlagNewVolume, + Value: cli.NewStringSlice(), + Usage: FlagNewVolumeUsage, + EnvVars: []string{"DSLIM_NEW_VOLUME"}, + }, + FlagNewLabel: &cli.StringSliceFlag{ + Name: FlagNewLabel, + Value: cli.NewStringSlice(), + Usage: FlagNewLabelUsage, + EnvVars: []string{"DSLIM_NEW_LABEL"}, + }, + FlagTag: &cli.StringSliceFlag{ + Name: FlagTag, + Value: cli.NewStringSlice(), + Usage: FlagTagUsage, + EnvVars: []string{"DSLIM_TARGET_TAG"}, + }, + FlagImageOverrides: &cli.StringFlag{ + Name: FlagImageOverrides, + Value: "", + Usage: FlagImageOverridesUsage, + EnvVars: []string{"DSLIM_TARGET_OVERRIDES"}, }, //Container Build Options - FlagBuildFromDockerfile: cli.StringFlag{ - Name: FlagBuildFromDockerfile, - Value: "", - Usage: FlagBuildFromDockerfileUsage, - EnvVar: "DSLIM_BUILD_DOCKERFILE", - }, - FlagDockerfileContext: cli.StringFlag{ - Name: FlagDockerfileContext, - Value: "", - Usage: FlagDockerfileContextUsage, - EnvVar: "DSLIM_BUILD_DOCKERFILE_CTX", - }, - FlagTagFat: cli.StringFlag{ - Name: FlagTagFat, - Value: "", - Usage: FlagTagFatUsage, - EnvVar: "DSLIM_TARGET_TAG_FAT", - }, - FlagCBOAddHost: cli.StringSliceFlag{ - Name: FlagCBOAddHost, - Value: &cli.StringSlice{}, - Usage: FlagCBOAddHostUsage, - EnvVar: "DSLIM_CBO_ADD_HOST", - }, - FlagCBOBuildArg: cli.StringSliceFlag{ - Name: FlagCBOBuildArg, - Value: &cli.StringSlice{}, - Usage: FlagCBOBuildArgUsage, - EnvVar: "DSLIM_CBO_BUILD_ARG", - }, - FlagCBOCacheFrom: cli.StringSliceFlag{ - Name: FlagCBOCacheFrom, - Value: &cli.StringSlice{}, - Usage: FlagCBOCacheFromUsage, - EnvVar: "DSLIM_CBO_CACHE_FROM", - }, - FlagCBOLabel: cli.StringSliceFlag{ - Name: FlagCBOLabel, - Value: &cli.StringSlice{}, - Usage: FlagCBOLabelUsage, - EnvVar: "DSLIM_CBO_LABEL", - }, - FlagCBOTarget: cli.StringFlag{ - Name: FlagCBOTarget, - Value: "", - Usage: FlagCBOTargetUsage, - EnvVar: "DSLIM_CBO_TARGET", - }, - FlagCBONetwork: cli.StringFlag{ - Name: FlagCBONetwork, - Value: "", - Usage: FlagCBONetworkUsage, - EnvVar: "DSLIM_CBO_NETWORK", - }, - FlagDeleteFatImage: cli.BoolFlag{ - Name: FlagDeleteFatImage, - Usage: FlagDeleteFatImageUsage, - EnvVar: "DSLIM_DELETE_FAT", - }, - FlagRemoveExpose: cli.StringSliceFlag{ - Name: FlagRemoveExpose, - Value: &cli.StringSlice{}, - Usage: FlagRemoveExposeUsage, - EnvVar: "DSLIM_RM_EXPOSE", - }, - FlagRemoveEnv: cli.StringSliceFlag{ - Name: FlagRemoveEnv, - Value: &cli.StringSlice{}, - Usage: FlagRemoveEnvUsage, - EnvVar: "DSLIM_RM_ENV", - }, - FlagRemoveLabel: cli.StringSliceFlag{ - Name: FlagRemoveLabel, - Value: &cli.StringSlice{}, - Usage: FlagRemoveLabelUsage, - EnvVar: "DSLIM_RM_LABEL", - }, - FlagRemoveVolume: cli.StringSliceFlag{ - Name: FlagRemoveVolume, - Value: &cli.StringSlice{}, - Usage: FlagRemoveVolumeUsage, - EnvVar: "DSLIM_RM_VOLUME", - }, - FlagIncludeBinFile: cli.StringFlag{ - Name: FlagIncludeBinFile, - Value: "", - Usage: FlagIncludeBinFileUsage, - EnvVar: "DSLIM_INCLUDE_BIN_FILE", - }, - FlagIncludeExeFile: cli.StringFlag{ - Name: FlagIncludeExeFile, - Value: "", - Usage: FlagIncludeExeFileUsage, - EnvVar: "DSLIM_INCLUDE_EXE_FILE", + FlagBuildFromDockerfile: &cli.StringFlag{ + Name: FlagBuildFromDockerfile, + Value: "", + Usage: FlagBuildFromDockerfileUsage, + EnvVars: []string{"DSLIM_BUILD_DOCKERFILE"}, + }, + FlagDockerfileContext: &cli.StringFlag{ + Name: FlagDockerfileContext, + Value: "", + Usage: FlagDockerfileContextUsage, + EnvVars: []string{"DSLIM_BUILD_DOCKERFILE_CTX"}, + }, + FlagTagFat: &cli.StringFlag{ + Name: FlagTagFat, + Value: "", + Usage: FlagTagFatUsage, + EnvVars: []string{"DSLIM_TARGET_TAG_FAT"}, + }, + FlagCBOAddHost: &cli.StringSliceFlag{ + Name: FlagCBOAddHost, + Value: cli.NewStringSlice(), + Usage: FlagCBOAddHostUsage, + EnvVars: []string{"DSLIM_CBO_ADD_HOST"}, + }, + FlagCBOBuildArg: &cli.StringSliceFlag{ + Name: FlagCBOBuildArg, + Value: cli.NewStringSlice(), + Usage: FlagCBOBuildArgUsage, + EnvVars: []string{"DSLIM_CBO_BUILD_ARG"}, + }, + FlagCBOCacheFrom: &cli.StringSliceFlag{ + Name: FlagCBOCacheFrom, + Value: cli.NewStringSlice(), + Usage: FlagCBOCacheFromUsage, + EnvVars: []string{"DSLIM_CBO_CACHE_FROM"}, + }, + FlagCBOLabel: &cli.StringSliceFlag{ + Name: FlagCBOLabel, + Value: cli.NewStringSlice(), + Usage: FlagCBOLabelUsage, + EnvVars: []string{"DSLIM_CBO_LABEL"}, + }, + FlagCBOTarget: &cli.StringFlag{ + Name: FlagCBOTarget, + Value: "", + Usage: FlagCBOTargetUsage, + EnvVars: []string{"DSLIM_CBO_TARGET"}, + }, + FlagCBONetwork: &cli.StringFlag{ + Name: FlagCBONetwork, + Value: "", + Usage: FlagCBONetworkUsage, + EnvVars: []string{"DSLIM_CBO_NETWORK"}, + }, + FlagDeleteFatImage: &cli.BoolFlag{ + Name: FlagDeleteFatImage, + Usage: FlagDeleteFatImageUsage, + EnvVars: []string{"DSLIM_DELETE_FAT"}, + }, + FlagRemoveExpose: &cli.StringSliceFlag{ + Name: FlagRemoveExpose, + Value: cli.NewStringSlice(), + Usage: FlagRemoveExposeUsage, + EnvVars: []string{"DSLIM_RM_EXPOSE"}, + }, + FlagRemoveEnv: &cli.StringSliceFlag{ + Name: FlagRemoveEnv, + Value: cli.NewStringSlice(), + Usage: FlagRemoveEnvUsage, + EnvVars: []string{"DSLIM_RM_ENV"}, + }, + FlagRemoveLabel: &cli.StringSliceFlag{ + Name: FlagRemoveLabel, + Value: cli.NewStringSlice(), + Usage: FlagRemoveLabelUsage, + EnvVars: []string{"DSLIM_RM_LABEL"}, + }, + FlagRemoveVolume: &cli.StringSliceFlag{ + Name: FlagRemoveVolume, + Value: cli.NewStringSlice(), + Usage: FlagRemoveVolumeUsage, + EnvVars: []string{"DSLIM_RM_VOLUME"}, + }, + FlagIncludeBinFile: &cli.StringFlag{ + Name: FlagIncludeBinFile, + Value: "", + Usage: FlagIncludeBinFileUsage, + EnvVars: []string{"DSLIM_INCLUDE_BIN_FILE"}, + }, + FlagIncludeExeFile: &cli.StringFlag{ + Name: FlagIncludeExeFile, + Value: "", + Usage: FlagIncludeExeFileUsage, + EnvVars: []string{"DSLIM_INCLUDE_EXE_FILE"}, }, } diff --git a/pkg/app/master/commands/cliflags.go b/pkg/app/master/commands/cliflags.go index d6b6850c25..1ec0b1b4ed 100644 --- a/pkg/app/master/commands/cliflags.go +++ b/pkg/app/master/commands/cliflags.go @@ -2,7 +2,7 @@ package commands import ( log "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) ///////////////////////////////////////////////////////// @@ -232,71 +232,74 @@ const ( func GlobalFlags() []cli.Flag { return []cli.Flag{ - cli.StringFlag{ + &cli.StringFlag{ Name: FlagCommandReport, Value: "slim.report.json", Usage: "command report location (enabled by default; set it to \"off\" to disable it)", }, - cli.BoolTFlag{ - Name: FlagCheckVersion, - Usage: "check if the current version is outdated", - EnvVar: "DSLIM_CHECK_VERSION", + &cli.BoolFlag{ + Name: FlagCheckVersion, + Value: true, + Usage: "check if the current version is outdated", + EnvVars: []string{"DSLIM_CHECK_VERSION"}, }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: FlagDebug, Usage: FlagDebugUsage, }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: FlagVerbose, Usage: "enable info logs", }, - cli.StringFlag{ + &cli.StringFlag{ Name: FlagLogLevel, Value: "warn", Usage: "set the logging level ('debug', 'info', 'warn' (default), 'error', 'fatal', 'panic')", }, - cli.StringFlag{ + &cli.StringFlag{ Name: FlagLog, Usage: "log file to store logs", }, - cli.StringFlag{ + &cli.StringFlag{ Name: FlagLogFormat, Value: "text", Usage: "set the format used by logs ('text' (default), or 'json')", }, - cli.BoolTFlag{ + &cli.BoolFlag{ Name: FlagUseTLS, + Value: true, Usage: "use TLS", }, - cli.BoolTFlag{ + &cli.BoolFlag{ Name: FlagVerifyTLS, + Value: true, Usage: "verify TLS", }, - cli.StringFlag{ + &cli.StringFlag{ Name: FlagTLSCertPath, Value: "", Usage: "path to TLS cert files", }, - cli.StringFlag{ + &cli.StringFlag{ Name: FlagHost, Value: "", Usage: "Docker host address", }, - cli.StringFlag{ + &cli.StringFlag{ Name: FlagStatePath, Value: "", Usage: "DockerSlim state base path", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: FlagInContainer, Usage: "DockerSlim is running in a container", }, - cli.StringFlag{ + &cli.StringFlag{ Name: FlagArchiveState, Value: "", Usage: "archive DockerSlim state to the selected Docker volume (default volume - docker-slim-state). By default, enabled when DockerSlim is running in a container (disabled otherwise). Set it to \"off\" to disable explicitly.", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: FlagNoColor, Usage: FlagNoColorUsage, }, @@ -304,434 +307,439 @@ func GlobalFlags() []cli.Flag { } var CommonFlags = map[string]cli.Flag{ - FlagTarget: cli.StringFlag{ - Name: FlagTarget, - Value: "", - Usage: FlagTargetUsage, - EnvVar: "DSLIM_TARGET", - }, - FlagPull: cli.BoolFlag{ - Name: FlagPull, - Usage: FlagPullUsage, - EnvVar: "DSLIM_PULL", - }, - FlagDockerConfigPath: cli.StringFlag{ - Name: FlagDockerConfigPath, - Usage: FlagDockerConfigPathUsage, - EnvVar: "DSLIM_DOCKER_CONFIG_PATH", - }, - FlagRegistryAccount: cli.StringFlag{ - Name: FlagRegistryAccount, - Usage: FlagRegistryAccountUsage, - EnvVar: "DSLIM_REGISTRY_ACCOUNT", - }, - FlagRegistrySecret: cli.StringFlag{ - Name: FlagRegistrySecret, - Usage: FlagRegistrySecretUsage, - EnvVar: "DSLIM_REGISTRY_SECRET", - }, - FlagShowPullLogs: cli.BoolFlag{ - Name: FlagShowPullLogs, - Usage: FlagShowPullLogsUsage, - EnvVar: "DSLIM_PLOG", - }, - FlagComposeFile: cli.StringSliceFlag{ - Name: FlagComposeFile, - Value: &cli.StringSlice{}, - Usage: FlagComposeFileUsage, - EnvVar: "DSLIM_COMPOSE_FILE", - }, - FlagTargetComposeSvc: cli.StringFlag{ - Name: FlagTargetComposeSvc, - Value: "", - Usage: FlagTargetComposeSvcUsage, - EnvVar: "DSLIM_TARGET_COMPOSE_SVC", - }, - FlagComposeSvcNoPorts: cli.BoolFlag{ - Name: FlagComposeSvcNoPorts, - Usage: FlagComposeSvcNoPortsUsage, - EnvVar: "DSLIM_COMPOSE_SVC_NO_PORTS", - }, - FlagDepExcludeComposeSvcAll: cli.BoolFlag{ - Name: FlagDepExcludeComposeSvcAll, - Usage: FlagDepExcludeComposeSvcAllUsage, - EnvVar: "DSLIM_DEP_INCLUDE_COMPOSE_SVC_ALL", - }, - FlagDepIncludeComposeSvcDeps: cli.StringFlag{ - Name: FlagDepIncludeComposeSvcDeps, - Value: "", - Usage: FlagDepIncludeComposeSvcDepsUsage, - EnvVar: "DSLIM_DEP_INCLUDE_COMPOSE_SVC_DEPS", - }, - FlagDepIncludeComposeSvc: cli.StringSliceFlag{ - Name: FlagDepIncludeComposeSvc, - Value: &cli.StringSlice{}, - Usage: FlagDepIncludeComposeSvcUsage, - EnvVar: "DSLIM_DEP_INCLUDE_COMPOSE_SVC", - }, - FlagDepExcludeComposeSvc: cli.StringSliceFlag{ - Name: FlagDepExcludeComposeSvc, - Value: &cli.StringSlice{}, - Usage: FlagDepExcludeComposeSvcUsage, - EnvVar: "DSLIM_DEP_EXCLUDE_COMPOSE_SVC", - }, - FlagComposeNet: cli.StringSliceFlag{ - Name: FlagComposeNet, - Value: &cli.StringSlice{}, - Usage: FlagComposeNetUsage, - EnvVar: "DSLIM_COMPOSE_NET", - }, - FlagDepIncludeTargetComposeSvcDeps: cli.BoolFlag{ - Name: FlagDepIncludeTargetComposeSvcDeps, - Usage: FlagDepIncludeTargetComposeSvcDepsUsage, - EnvVar: "DSLIM_DEP_INCLUDE_TARGET_COMPOSE_SVC_DEPS", - }, - FlagComposeEnvNoHost: cli.BoolFlag{ - Name: FlagComposeEnvNoHost, - Usage: FlagComposeEnvNoHostUsage, - EnvVar: "DSLIM_COMPOSE_ENV_NOHOST", - }, - FlagComposeEnvFile: cli.StringFlag{ - Name: FlagComposeEnvFile, - Value: "", - Usage: FlagComposeEnvFileUsage, - EnvVar: "DSLIM_COMPOSE_ENV_FILE", - }, - FlagComposeProjectName: cli.StringFlag{ - Name: FlagComposeProjectName, - Value: "", - Usage: FlagComposeProjectNameUsage, - EnvVar: "DSLIM_COMPOSE_PROJECT_NAME", - }, - FlagComposeWorkdir: cli.StringFlag{ - Name: FlagComposeWorkdir, - Value: "", - Usage: FlagComposeWorkdirUsage, - EnvVar: "DSLIM_COMPOSE_WORKDIR", - }, - FlagContainerProbeComposeSvc: cli.StringFlag{ - Name: FlagContainerProbeComposeSvc, - Value: "", - Usage: FlagContainerProbeComposeSvcUsage, - EnvVar: "DSLIM_CONTAINER_PROBE_COMPOSE_SVC", - }, - FlagPrestartComposeSvc: cli.StringSliceFlag{ - Name: FlagPrestartComposeSvc, - Value: &cli.StringSlice{}, - Usage: FlagPrestartComposeSvcUsage, - EnvVar: "DSLIM_PRESTART_COMPOSE_SVC", - }, - FlagPrestartComposeWaitExit: cli.BoolFlag{ - Name: FlagPrestartComposeWaitExit, - Usage: FlagPrestartComposeWaitExitUsage, - EnvVar: "DSLIM_PRESTART_COMPOSE_WAIT", - }, - FlagPoststartComposeSvc: cli.StringSliceFlag{ - Name: FlagPoststartComposeSvc, - Value: &cli.StringSlice{}, - Usage: FlagPoststartComposeSvcUsage, - EnvVar: "DSLIM_POSTSTART_COMPOSE_SVC", - }, - FlagRemoveFileArtifacts: cli.BoolFlag{ - Name: FlagRemoveFileArtifacts, - Usage: FlagRemoveFileArtifactsUsage, - EnvVar: "DSLIM_RM_FILE_ARTIFACTS", - }, - FlagCopyMetaArtifacts: cli.StringFlag{ - Name: FlagCopyMetaArtifacts, - Usage: FlagCopyMetaArtifactsUsage, - EnvVar: "DSLIM_CP_META_ARTIFACTS", + FlagTarget: &cli.StringFlag{ + Name: FlagTarget, + Value: "", + Usage: FlagTargetUsage, + EnvVars: []string{"DSLIM_TARGET"}, + }, + FlagPull: &cli.BoolFlag{ + Name: FlagPull, + Usage: FlagPullUsage, + EnvVars: []string{"DSLIM_PULL"}, + }, + FlagDockerConfigPath: &cli.StringFlag{ + Name: FlagDockerConfigPath, + Usage: FlagDockerConfigPathUsage, + EnvVars: []string{"DSLIM_DOCKER_CONFIG_PATH"}, + }, + FlagRegistryAccount: &cli.StringFlag{ + Name: FlagRegistryAccount, + Usage: FlagRegistryAccountUsage, + EnvVars: []string{"DSLIM_REGISTRY_ACCOUNT"}, + }, + FlagRegistrySecret: &cli.StringFlag{ + Name: FlagRegistrySecret, + Usage: FlagRegistrySecretUsage, + EnvVars: []string{"DSLIM_REGISTRY_SECRET"}, + }, + FlagShowPullLogs: &cli.BoolFlag{ + Name: FlagShowPullLogs, + Usage: FlagShowPullLogsUsage, + EnvVars: []string{"DSLIM_PLOG"}, + }, + FlagComposeFile: &cli.StringSliceFlag{ + Name: FlagComposeFile, + Value: cli.NewStringSlice(), + Usage: FlagComposeFileUsage, + EnvVars: []string{"DSLIM_COMPOSE_FILE"}, + }, + FlagTargetComposeSvc: &cli.StringFlag{ + Name: FlagTargetComposeSvc, + Value: "", + Usage: FlagTargetComposeSvcUsage, + EnvVars: []string{"DSLIM_TARGET_COMPOSE_SVC"}, + }, + FlagComposeSvcNoPorts: &cli.BoolFlag{ + Name: FlagComposeSvcNoPorts, + Usage: FlagComposeSvcNoPortsUsage, + EnvVars: []string{"DSLIM_COMPOSE_SVC_NO_PORTS"}, + }, + FlagDepExcludeComposeSvcAll: &cli.BoolFlag{ + Name: FlagDepExcludeComposeSvcAll, + Usage: FlagDepExcludeComposeSvcAllUsage, + EnvVars: []string{"DSLIM_DEP_INCLUDE_COMPOSE_SVC_ALL"}, + }, + FlagDepIncludeComposeSvcDeps: &cli.StringFlag{ + Name: FlagDepIncludeComposeSvcDeps, + Value: "", + Usage: FlagDepIncludeComposeSvcDepsUsage, + EnvVars: []string{"DSLIM_DEP_INCLUDE_COMPOSE_SVC_DEPS"}, + }, + FlagDepIncludeComposeSvc: &cli.StringSliceFlag{ + Name: FlagDepIncludeComposeSvc, + Value: cli.NewStringSlice(), + Usage: FlagDepIncludeComposeSvcUsage, + EnvVars: []string{"DSLIM_DEP_INCLUDE_COMPOSE_SVC"}, + }, + FlagDepExcludeComposeSvc: &cli.StringSliceFlag{ + Name: FlagDepExcludeComposeSvc, + Value: cli.NewStringSlice(), + Usage: FlagDepExcludeComposeSvcUsage, + EnvVars: []string{"DSLIM_DEP_EXCLUDE_COMPOSE_SVC"}, + }, + FlagComposeNet: &cli.StringSliceFlag{ + Name: FlagComposeNet, + Value: cli.NewStringSlice(), + Usage: FlagComposeNetUsage, + EnvVars: []string{"DSLIM_COMPOSE_NET"}, + }, + FlagDepIncludeTargetComposeSvcDeps: &cli.BoolFlag{ + Name: FlagDepIncludeTargetComposeSvcDeps, + Usage: FlagDepIncludeTargetComposeSvcDepsUsage, + EnvVars: []string{"DSLIM_DEP_INCLUDE_TARGET_COMPOSE_SVC_DEPS"}, + }, + FlagComposeEnvNoHost: &cli.BoolFlag{ + Name: FlagComposeEnvNoHost, + Usage: FlagComposeEnvNoHostUsage, + EnvVars: []string{"DSLIM_COMPOSE_ENV_NOHOST"}, + }, + FlagComposeEnvFile: &cli.StringFlag{ + Name: FlagComposeEnvFile, + Value: "", + Usage: FlagComposeEnvFileUsage, + EnvVars: []string{"DSLIM_COMPOSE_ENV_FILE"}, + }, + FlagComposeProjectName: &cli.StringFlag{ + Name: FlagComposeProjectName, + Value: "", + Usage: FlagComposeProjectNameUsage, + EnvVars: []string{"DSLIM_COMPOSE_PROJECT_NAME"}, + }, + FlagComposeWorkdir: &cli.StringFlag{ + Name: FlagComposeWorkdir, + Value: "", + Usage: FlagComposeWorkdirUsage, + EnvVars: []string{"DSLIM_COMPOSE_WORKDIR"}, + }, + FlagContainerProbeComposeSvc: &cli.StringFlag{ + Name: FlagContainerProbeComposeSvc, + Value: "", + Usage: FlagContainerProbeComposeSvcUsage, + EnvVars: []string{"DSLIM_CONTAINER_PROBE_COMPOSE_SVC"}, + }, + FlagPrestartComposeSvc: &cli.StringSliceFlag{ + Name: FlagPrestartComposeSvc, + Value: cli.NewStringSlice(), + Usage: FlagPrestartComposeSvcUsage, + EnvVars: []string{"DSLIM_PRESTART_COMPOSE_SVC"}, + }, + FlagPrestartComposeWaitExit: &cli.BoolFlag{ + Name: FlagPrestartComposeWaitExit, + Usage: FlagPrestartComposeWaitExitUsage, + EnvVars: []string{"DSLIM_PRESTART_COMPOSE_WAIT"}, + }, + FlagPoststartComposeSvc: &cli.StringSliceFlag{ + Name: FlagPoststartComposeSvc, + Value: cli.NewStringSlice(), + Usage: FlagPoststartComposeSvcUsage, + EnvVars: []string{"DSLIM_POSTSTART_COMPOSE_SVC"}, + }, + FlagRemoveFileArtifacts: &cli.BoolFlag{ + Name: FlagRemoveFileArtifacts, + Usage: FlagRemoveFileArtifactsUsage, + EnvVars: []string{"DSLIM_RM_FILE_ARTIFACTS"}, + }, + FlagCopyMetaArtifacts: &cli.StringFlag{ + Name: FlagCopyMetaArtifacts, + Usage: FlagCopyMetaArtifactsUsage, + EnvVars: []string{"DSLIM_CP_META_ARTIFACTS"}, }, // - FlagHTTPProbe: cli.BoolTFlag{ //true by default - Name: FlagHTTPProbe, - Usage: FlagHTTPProbeUsage, - EnvVar: "DSLIM_HTTP_PROBE", - }, - FlagHTTPProbeOff: cli.BoolFlag{ - Name: FlagHTTPProbeOff, - Usage: FlagHTTPProbeOffUsage, - EnvVar: "DSLIM_HTTP_PROBE_OFF", - }, - FlagHTTPProbeCmd: cli.StringSliceFlag{ - Name: FlagHTTPProbeCmd, - Value: &cli.StringSlice{}, - Usage: FlagHTTPProbeCmdUsage, - EnvVar: "DSLIM_HTTP_PROBE_CMD", - }, - FlagHTTPProbeCmdFile: cli.StringFlag{ - Name: FlagHTTPProbeCmdFile, - Value: "", - Usage: FlagHTTPProbeCmdFileUsage, - EnvVar: "DSLIM_HTTP_PROBE_CMD_FILE", - }, - FlagHTTPProbeAPISpec: cli.StringSliceFlag{ - Name: FlagHTTPProbeAPISpec, - Value: &cli.StringSlice{}, - Usage: FlagHTTPProbeAPISpecUsage, - EnvVar: "DSLIM_HTTP_PROBE_API_SPEC", - }, - FlagHTTPProbeAPISpecFile: cli.StringSliceFlag{ - Name: FlagHTTPProbeAPISpecFile, - Value: &cli.StringSlice{}, - Usage: FlagHTTPProbeAPISpecFileUsage, - EnvVar: "DSLIM_HTTP_PROBE_API_SPEC_FILE", - }, - FlagHTTPProbeStartWait: cli.IntFlag{ - Name: FlagHTTPProbeStartWait, - Value: 0, - Usage: FlagHTTPProbeStartWaitUsage, - EnvVar: "DSLIM_HTTP_PROBE_START_WAIT", - }, - FlagHTTPProbeRetryCount: cli.IntFlag{ - Name: FlagHTTPProbeRetryCount, - Value: 5, - Usage: FlagHTTPProbeRetryCountUsage, - EnvVar: "DSLIM_HTTP_PROBE_RETRY_COUNT", - }, - FlagHTTPProbeRetryWait: cli.IntFlag{ - Name: FlagHTTPProbeRetryWait, - Value: 8, - Usage: FlagHTTPProbeRetryWaitUsage, - EnvVar: "DSLIM_HTTP_PROBE_RETRY_WAIT", - }, - FlagHTTPProbePorts: cli.StringFlag{ - Name: FlagHTTPProbePorts, - Value: "", - Usage: FlagHTTPProbePortsUsage, - EnvVar: "DSLIM_HTTP_PROBE_PORTS", - }, - FlagHTTPProbeFull: cli.BoolFlag{ - Name: FlagHTTPProbeFull, - Usage: FlagHTTPProbeFullUsage, - EnvVar: "DSLIM_HTTP_PROBE_FULL", - }, - FlagHTTPProbeExitOnFailure: cli.BoolTFlag{ //true by default now - Name: FlagHTTPProbeExitOnFailure, - Usage: FlagHTTPProbeExitOnFailureUsage, - EnvVar: "DSLIM_HTTP_PROBE_EXIT_ON_FAILURE", - }, - FlagHTTPProbeCrawl: cli.BoolTFlag{ - Name: FlagHTTPProbeCrawl, - Usage: FlagHTTPProbeCrawl, - EnvVar: "DSLIM_HTTP_PROBE_CRAWL", - }, - FlagHTTPCrawlMaxDepth: cli.IntFlag{ - Name: FlagHTTPCrawlMaxDepth, - Value: 3, - Usage: FlagHTTPCrawlMaxDepthUsage, - EnvVar: "DSLIM_HTTP_CRAWL_MAX_DEPTH", - }, - FlagHTTPCrawlMaxPageCount: cli.IntFlag{ - Name: FlagHTTPCrawlMaxPageCount, - Value: 1000, - Usage: FlagHTTPCrawlMaxPageCountUsage, - EnvVar: "DSLIM_HTTP_CRAWL_MAX_PAGE_COUNT", - }, - FlagHTTPCrawlConcurrency: cli.IntFlag{ - Name: FlagHTTPCrawlConcurrency, - Value: 10, - Usage: FlagHTTPCrawlConcurrencyUsage, - EnvVar: "DSLIM_HTTP_CRAWL_CONCURRENCY", - }, - FlagHTTPMaxConcurrentCrawlers: cli.IntFlag{ - Name: FlagHTTPMaxConcurrentCrawlers, - Value: 1, - Usage: FlagHTTPMaxConcurrentCrawlersUsage, - EnvVar: "DSLIM_HTTP_MAX_CONCURRENT_CRAWLERS", - }, - FlagHTTPProbeExec: cli.StringSliceFlag{ - Name: FlagHTTPProbeExec, - Value: &cli.StringSlice{}, - Usage: FlagHTTPProbeExecUsage, - EnvVar: "DSLIM_HTTP_PROBE_EXEC", - }, - FlagHTTPProbeExecFile: cli.StringFlag{ - Name: FlagHTTPProbeExecFile, - Value: "", - Usage: FlagHTTPProbeExecFileUsage, - EnvVar: "DSLIM_HTTP_PROBE_EXEC_FILE", - }, - FlagPublishPort: cli.StringSliceFlag{ - Name: FlagPublishPort, - Value: &cli.StringSlice{}, - Usage: FlagPublishPortUsage, - EnvVar: "DSLIM_PUBLISH_PORT", - }, - FlagPublishExposedPorts: cli.BoolFlag{ - Name: FlagPublishExposedPorts, - Usage: FlagPublishExposedPortsUsage, - EnvVar: "DSLIM_PUBLISH_EXPOSED", - }, - FlagRunTargetAsUser: cli.BoolTFlag{ - Name: FlagRunTargetAsUser, - Usage: FlagRunTargetAsUserUsage, - EnvVar: "DSLIM_RUN_TAS_USER", - }, - FlagShowContainerLogs: cli.BoolFlag{ - Name: FlagShowContainerLogs, - Usage: FlagShowContainerLogsUsage, - EnvVar: "DSLIM_SHOW_CLOGS", - }, - FlagExec: cli.StringFlag{ - Name: FlagExec, - Value: "", - Usage: FlagExecUsage, - EnvVar: "DSLIM_RC_EXE", - }, - FlagExecFile: cli.StringFlag{ - Name: FlagExecFile, - Value: "", - Usage: FlagExecFileUsage, - EnvVar: "DSLIM_RC_EXE_FILE", - }, - FlagExcludeMounts: cli.BoolTFlag{ - Name: FlagExcludeMounts, //true by default - Usage: FlagExcludeMountsUsage, - EnvVar: "DSLIM_EXCLUDE_MOUNTS", - }, - FlagExcludePattern: cli.StringSliceFlag{ - Name: FlagExcludePattern, - Value: &cli.StringSlice{}, - Usage: FlagExcludePatternUsage, - EnvVar: "DSLIM_EXCLUDE_PATTERN", - }, - FlagUseLocalMounts: cli.BoolFlag{ - Name: FlagUseLocalMounts, - Usage: FlagUseLocalMountsUsage, - EnvVar: "DSLIM_USE_LOCAL_MOUNTS", - }, - FlagUseSensorVolume: cli.StringFlag{ - Name: FlagUseSensorVolume, - Value: "", - Usage: FlagUseSensorVolumeUsage, - EnvVar: "DSLIM_USE_SENSOR_VOLUME", - }, - FlagContinueAfter: cli.StringFlag{ - Name: FlagContinueAfter, - Value: "probe", - Usage: FlagContinueAfterUsage, - EnvVar: "DSLIM_CONTINUE_AFTER", + FlagHTTPProbe: &cli.BoolFlag{ //true by default + Name: FlagHTTPProbe, + Value: true, + Usage: FlagHTTPProbeUsage, + EnvVars: []string{"DSLIM_HTTP_PROBE"}, + }, + FlagHTTPProbeOff: &cli.BoolFlag{ + Name: FlagHTTPProbeOff, + Usage: FlagHTTPProbeOffUsage, + EnvVars: []string{"DSLIM_HTTP_PROBE_OFF"}, + }, + FlagHTTPProbeCmd: &cli.StringSliceFlag{ + Name: FlagHTTPProbeCmd, + Value: cli.NewStringSlice(), + Usage: FlagHTTPProbeCmdUsage, + EnvVars: []string{"DSLIM_HTTP_PROBE_CMD"}, + }, + FlagHTTPProbeCmdFile: &cli.StringFlag{ + Name: FlagHTTPProbeCmdFile, + Value: "", + Usage: FlagHTTPProbeCmdFileUsage, + EnvVars: []string{"DSLIM_HTTP_PROBE_CMD_FILE"}, + }, + FlagHTTPProbeAPISpec: &cli.StringSliceFlag{ + Name: FlagHTTPProbeAPISpec, + Value: cli.NewStringSlice(), + Usage: FlagHTTPProbeAPISpecUsage, + EnvVars: []string{"DSLIM_HTTP_PROBE_API_SPEC"}, + }, + FlagHTTPProbeAPISpecFile: &cli.StringSliceFlag{ + Name: FlagHTTPProbeAPISpecFile, + Value: cli.NewStringSlice(), + Usage: FlagHTTPProbeAPISpecFileUsage, + EnvVars: []string{"DSLIM_HTTP_PROBE_API_SPEC_FILE"}, + }, + FlagHTTPProbeStartWait: &cli.IntFlag{ + Name: FlagHTTPProbeStartWait, + Value: 0, + Usage: FlagHTTPProbeStartWaitUsage, + EnvVars: []string{"DSLIM_HTTP_PROBE_START_WAIT"}, + }, + FlagHTTPProbeRetryCount: &cli.IntFlag{ + Name: FlagHTTPProbeRetryCount, + Value: 5, + Usage: FlagHTTPProbeRetryCountUsage, + EnvVars: []string{"DSLIM_HTTP_PROBE_RETRY_COUNT"}, + }, + FlagHTTPProbeRetryWait: &cli.IntFlag{ + Name: FlagHTTPProbeRetryWait, + Value: 8, + Usage: FlagHTTPProbeRetryWaitUsage, + EnvVars: []string{"DSLIM_HTTP_PROBE_RETRY_WAIT"}, + }, + FlagHTTPProbePorts: &cli.StringFlag{ + Name: FlagHTTPProbePorts, + Value: "", + Usage: FlagHTTPProbePortsUsage, + EnvVars: []string{"DSLIM_HTTP_PROBE_PORTS"}, + }, + FlagHTTPProbeFull: &cli.BoolFlag{ + Name: FlagHTTPProbeFull, + Usage: FlagHTTPProbeFullUsage, + EnvVars: []string{"DSLIM_HTTP_PROBE_FULL"}, + }, + FlagHTTPProbeExitOnFailure: &cli.BoolFlag{ //true by default now + Name: FlagHTTPProbeExitOnFailure, + Value: true, + Usage: FlagHTTPProbeExitOnFailureUsage, + EnvVars: []string{"DSLIM_HTTP_PROBE_EXIT_ON_FAILURE"}, + }, + FlagHTTPProbeCrawl: &cli.BoolFlag{ + Name: FlagHTTPProbeCrawl, + Value: true, + Usage: FlagHTTPProbeCrawl, + EnvVars: []string{"DSLIM_HTTP_PROBE_CRAWL"}, + }, + FlagHTTPCrawlMaxDepth: &cli.IntFlag{ + Name: FlagHTTPCrawlMaxDepth, + Value: 3, + Usage: FlagHTTPCrawlMaxDepthUsage, + EnvVars: []string{"DSLIM_HTTP_CRAWL_MAX_DEPTH"}, + }, + FlagHTTPCrawlMaxPageCount: &cli.IntFlag{ + Name: FlagHTTPCrawlMaxPageCount, + Value: 1000, + Usage: FlagHTTPCrawlMaxPageCountUsage, + EnvVars: []string{"DSLIM_HTTP_CRAWL_MAX_PAGE_COUNT"}, + }, + FlagHTTPCrawlConcurrency: &cli.IntFlag{ + Name: FlagHTTPCrawlConcurrency, + Value: 10, + Usage: FlagHTTPCrawlConcurrencyUsage, + EnvVars: []string{"DSLIM_HTTP_CRAWL_CONCURRENCY"}, + }, + FlagHTTPMaxConcurrentCrawlers: &cli.IntFlag{ + Name: FlagHTTPMaxConcurrentCrawlers, + Value: 1, + Usage: FlagHTTPMaxConcurrentCrawlersUsage, + EnvVars: []string{"DSLIM_HTTP_MAX_CONCURRENT_CRAWLERS"}, + }, + FlagHTTPProbeExec: &cli.StringSliceFlag{ + Name: FlagHTTPProbeExec, + Value: cli.NewStringSlice(), + Usage: FlagHTTPProbeExecUsage, + EnvVars: []string{"DSLIM_HTTP_PROBE_EXEC"}, + }, + FlagHTTPProbeExecFile: &cli.StringFlag{ + Name: FlagHTTPProbeExecFile, + Value: "", + Usage: FlagHTTPProbeExecFileUsage, + EnvVars: []string{"DSLIM_HTTP_PROBE_EXEC_FILE"}, + }, + FlagPublishPort: &cli.StringSliceFlag{ + Name: FlagPublishPort, + Value: cli.NewStringSlice(), + Usage: FlagPublishPortUsage, + EnvVars: []string{"DSLIM_PUBLISH_PORT"}, + }, + FlagPublishExposedPorts: &cli.BoolFlag{ + Name: FlagPublishExposedPorts, + Usage: FlagPublishExposedPortsUsage, + EnvVars: []string{"DSLIM_PUBLISH_EXPOSED"}, + }, + FlagRunTargetAsUser: &cli.BoolFlag{ + Name: FlagRunTargetAsUser, + Value: true, + Usage: FlagRunTargetAsUserUsage, + EnvVars: []string{"DSLIM_RUN_TAS_USER"}, + }, + FlagShowContainerLogs: &cli.BoolFlag{ + Name: FlagShowContainerLogs, + Usage: FlagShowContainerLogsUsage, + EnvVars: []string{"DSLIM_SHOW_CLOGS"}, + }, + FlagExec: &cli.StringFlag{ + Name: FlagExec, + Value: "", + Usage: FlagExecUsage, + EnvVars: []string{"DSLIM_RC_EXE"}, + }, + FlagExecFile: &cli.StringFlag{ + Name: FlagExecFile, + Value: "", + Usage: FlagExecFileUsage, + EnvVars: []string{"DSLIM_RC_EXE_FILE"}, + }, + FlagExcludeMounts: &cli.BoolFlag{ + Name: FlagExcludeMounts, //true by default + Value: true, + Usage: FlagExcludeMountsUsage, + EnvVars: []string{"DSLIM_EXCLUDE_MOUNTS"}, + }, + FlagExcludePattern: &cli.StringSliceFlag{ + Name: FlagExcludePattern, + Value: cli.NewStringSlice(), + Usage: FlagExcludePatternUsage, + EnvVars: []string{"DSLIM_EXCLUDE_PATTERN"}, + }, + FlagUseLocalMounts: &cli.BoolFlag{ + Name: FlagUseLocalMounts, + Usage: FlagUseLocalMountsUsage, + EnvVars: []string{"DSLIM_USE_LOCAL_MOUNTS"}, + }, + FlagUseSensorVolume: &cli.StringFlag{ + Name: FlagUseSensorVolume, + Value: "", + Usage: FlagUseSensorVolumeUsage, + EnvVars: []string{"DSLIM_USE_SENSOR_VOLUME"}, + }, + FlagContinueAfter: &cli.StringFlag{ + Name: FlagContinueAfter, + Value: "probe", + Usage: FlagContinueAfterUsage, + EnvVars: []string{"DSLIM_CONTINUE_AFTER"}, }, //Container Run Options - FlagCRORuntime: cli.StringFlag{ - Name: FlagCRORuntime, - Value: "", - Usage: FlagCRORuntimeUsage, - EnvVar: "DSLIM_CRO_RUNTIME", - }, - FlagCROHostConfigFile: cli.StringFlag{ - Name: FlagCROHostConfigFile, - Value: "", - Usage: FlagCROHostConfigFileUsage, - EnvVar: "DSLIM_CRO_HOST_CONFIG_FILE", - }, - FlagCROSysctl: cli.StringSliceFlag{ - Name: FlagCROSysctl, - Value: &cli.StringSlice{}, - Usage: FlagCROSysctlUsage, - EnvVar: "DSLIM_CRO_SYSCTL", - }, - FlagCROShmSize: cli.Int64Flag{ - Name: FlagCROShmSize, - Value: -1, - Usage: FlagCROShmSizeUsage, - EnvVar: "DSLIM_CRO_SHM_SIZE", - }, - FlagUser: cli.StringFlag{ - Name: FlagUser, - Value: "", - Usage: FlagUserUsage, - EnvVar: "DSLIM_RC_USER", - }, - FlagEntrypoint: cli.StringFlag{ - Name: FlagEntrypoint, - Value: "", - Usage: FlagEntrypointUsage, - EnvVar: "DSLIM_RC_ENTRYPOINT", - }, - FlagCmd: cli.StringFlag{ - Name: FlagCmd, - Value: "", - Usage: FlagCmdUsage, - EnvVar: "DSLIM_RC_CMD", - }, - FlagWorkdir: cli.StringFlag{ - Name: FlagWorkdir, - Value: "", - Usage: FlagWorkdirUsage, - EnvVar: "DSLIM_RC_WORKDIR", - }, - FlagEnv: cli.StringSliceFlag{ - Name: FlagEnv, - Value: &cli.StringSlice{}, - Usage: FlagEnvUsage, - EnvVar: "DSLIM_RC_ENV", - }, - FlagLabel: cli.StringSliceFlag{ - Name: FlagLabel, - Value: &cli.StringSlice{}, - Usage: FlagLabelUsage, - EnvVar: "DSLIM_RC_LABEL", - }, - FlagVolume: cli.StringSliceFlag{ - Name: FlagVolume, - Value: &cli.StringSlice{}, - Usage: FlagVolumeUsage, - EnvVar: "DSLIM_RC_VOLUME", - }, - FlagLink: cli.StringSliceFlag{ - Name: FlagLink, - Value: &cli.StringSlice{}, - Usage: FlagLinkUsage, - EnvVar: "DSLIM_RC_LINK", - }, - FlagEtcHostsMap: cli.StringSliceFlag{ - Name: FlagEtcHostsMap, - Value: &cli.StringSlice{}, - Usage: FlagEtcHostsMapUsage, - EnvVar: "DSLIM_RC_ETC_HOSTS_MAP", - }, - FlagContainerDNS: cli.StringSliceFlag{ - Name: FlagContainerDNS, - Value: &cli.StringSlice{}, - Usage: FlagContainerDNSUsage, - EnvVar: "DSLIM_RC_DNS", - }, - FlagContainerDNSSearch: cli.StringSliceFlag{ - Name: FlagContainerDNSSearch, - Value: &cli.StringSlice{}, - Usage: FlagContainerDNSSearchUsage, - EnvVar: "DSLIM_RC_DNS_SEARCH", - }, - FlagHostname: cli.StringFlag{ - Name: FlagHostname, - Value: "", - Usage: FlagHostnameUsage, - EnvVar: "DSLIM_RC_HOSTNAME", - }, - FlagNetwork: cli.StringFlag{ - Name: FlagNetwork, - Value: "", - Usage: FlagNetworkUsage, - EnvVar: "DSLIM_RC_NET", - }, - FlagExpose: cli.StringSliceFlag{ - Name: FlagExpose, - Value: &cli.StringSlice{}, - Usage: FlagExposeUsage, - EnvVar: "DSLIM_RC_EXPOSE", - }, - FlagMount: cli.StringSliceFlag{ - Name: FlagMount, - Value: &cli.StringSlice{}, - Usage: FlagMountUsage, - EnvVar: "DSLIM_MOUNT", - }, - FlagDeleteFatImage: cli.BoolFlag{ - Name: FlagDeleteFatImage, - Usage: FlagDeleteFatImageUsage, - EnvVar: "DSLIM_DELETE_FAT", + FlagCRORuntime: &cli.StringFlag{ + Name: FlagCRORuntime, + Value: "", + Usage: FlagCRORuntimeUsage, + EnvVars: []string{"DSLIM_CRO_RUNTIME"}, + }, + FlagCROHostConfigFile: &cli.StringFlag{ + Name: FlagCROHostConfigFile, + Value: "", + Usage: FlagCROHostConfigFileUsage, + EnvVars: []string{"DSLIM_CRO_HOST_CONFIG_FILE"}, + }, + FlagCROSysctl: &cli.StringSliceFlag{ + Name: FlagCROSysctl, + Value: cli.NewStringSlice(), + Usage: FlagCROSysctlUsage, + EnvVars: []string{"DSLIM_CRO_SYSCTL"}, + }, + FlagCROShmSize: &cli.Int64Flag{ + Name: FlagCROShmSize, + Value: -1, + Usage: FlagCROShmSizeUsage, + EnvVars: []string{"DSLIM_CRO_SHM_SIZE"}, + }, + FlagUser: &cli.StringFlag{ + Name: FlagUser, + Value: "", + Usage: FlagUserUsage, + EnvVars: []string{"DSLIM_RC_USER"}, + }, + FlagEntrypoint: &cli.StringFlag{ + Name: FlagEntrypoint, + Value: "", + Usage: FlagEntrypointUsage, + EnvVars: []string{"DSLIM_RC_ENTRYPOINT"}, + }, + FlagCmd: &cli.StringFlag{ + Name: FlagCmd, + Value: "", + Usage: FlagCmdUsage, + EnvVars: []string{"DSLIM_RC_CMD"}, + }, + FlagWorkdir: &cli.StringFlag{ + Name: FlagWorkdir, + Value: "", + Usage: FlagWorkdirUsage, + EnvVars: []string{"DSLIM_RC_WORKDIR"}, + }, + FlagEnv: &cli.StringSliceFlag{ + Name: FlagEnv, + Value: cli.NewStringSlice(), + Usage: FlagEnvUsage, + EnvVars: []string{"DSLIM_RC_ENV"}, + }, + FlagLabel: &cli.StringSliceFlag{ + Name: FlagLabel, + Value: cli.NewStringSlice(), + Usage: FlagLabelUsage, + EnvVars: []string{"DSLIM_RC_LABEL"}, + }, + FlagVolume: &cli.StringSliceFlag{ + Name: FlagVolume, + Value: cli.NewStringSlice(), + Usage: FlagVolumeUsage, + EnvVars: []string{"DSLIM_RC_VOLUME"}, + }, + FlagLink: &cli.StringSliceFlag{ + Name: FlagLink, + Value: cli.NewStringSlice(), + Usage: FlagLinkUsage, + EnvVars: []string{"DSLIM_RC_LINK"}, + }, + FlagEtcHostsMap: &cli.StringSliceFlag{ + Name: FlagEtcHostsMap, + Value: cli.NewStringSlice(), + Usage: FlagEtcHostsMapUsage, + EnvVars: []string{"DSLIM_RC_ETC_HOSTS_MAP"}, + }, + FlagContainerDNS: &cli.StringSliceFlag{ + Name: FlagContainerDNS, + Value: cli.NewStringSlice(), + Usage: FlagContainerDNSUsage, + EnvVars: []string{"DSLIM_RC_DNS"}, + }, + FlagContainerDNSSearch: &cli.StringSliceFlag{ + Name: FlagContainerDNSSearch, + Value: cli.NewStringSlice(), + Usage: FlagContainerDNSSearchUsage, + EnvVars: []string{"DSLIM_RC_DNS_SEARCH"}, + }, + FlagHostname: &cli.StringFlag{ + Name: FlagHostname, + Value: "", + Usage: FlagHostnameUsage, + EnvVars: []string{"DSLIM_RC_HOSTNAME"}, + }, + FlagNetwork: &cli.StringFlag{ + Name: FlagNetwork, + Value: "", + Usage: FlagNetworkUsage, + EnvVars: []string{"DSLIM_RC_NET"}, + }, + FlagExpose: &cli.StringSliceFlag{ + Name: FlagExpose, + Value: cli.NewStringSlice(), + Usage: FlagExposeUsage, + EnvVars: []string{"DSLIM_RC_EXPOSE"}, + }, + FlagMount: &cli.StringSliceFlag{ + Name: FlagMount, + Value: cli.NewStringSlice(), + Usage: FlagMountUsage, + EnvVars: []string{"DSLIM_MOUNT"}, + }, + FlagDeleteFatImage: &cli.BoolFlag{ + Name: FlagDeleteFatImage, + Usage: FlagDeleteFatImageUsage, + EnvVars: []string{"DSLIM_DELETE_FAT"}, }, } diff --git a/pkg/app/master/commands/clifvgetter.go b/pkg/app/master/commands/clifvgetter.go index 46df1ac95c..7d495b3188 100644 --- a/pkg/app/master/commands/clifvgetter.go +++ b/pkg/app/master/commands/clifvgetter.go @@ -15,7 +15,7 @@ import ( "github.com/docker-slim/docker-slim/pkg/app/master/docker/dockerclient" "github.com/docker-slim/docker-slim/pkg/app/master/signals" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func GetContainerRunOptions(ctx *cli.Context) (*config.ContainerRunOptions, error) { @@ -164,18 +164,18 @@ func GetContainerOverrides(ctx *cli.Context) (*config.ContainerOverrides, error) func GlobalFlagValues(ctx *cli.Context) (*GenericParams, error) { values := GenericParams{ - CheckVersion: ctx.GlobalBool(FlagCheckVersion), - Debug: ctx.GlobalBool(FlagDebug), - StatePath: ctx.GlobalString(FlagStatePath), - ReportLocation: ctx.GlobalString(FlagCommandReport), + CheckVersion: ctx.Bool(FlagCheckVersion), + Debug: ctx.Bool(FlagDebug), + StatePath: ctx.String(FlagStatePath), + ReportLocation: ctx.String(FlagCommandReport), } if values.ReportLocation == "off" { values.ReportLocation = "" } - values.InContainer, values.IsDSImage = IsInContainer(ctx.GlobalBool(FlagInContainer)) - values.ArchiveState = ArchiveState(ctx.GlobalString(FlagArchiveState), values.InContainer) + values.InContainer, values.IsDSImage = IsInContainer(ctx.Bool(FlagInContainer)) + values.ArchiveState = ArchiveState(ctx.String(FlagArchiveState), values.InContainer) values.ClientConfig = GetDockerClientConfig(ctx) @@ -184,10 +184,10 @@ func GlobalFlagValues(ctx *cli.Context) (*GenericParams, error) { func GetDockerClientConfig(ctx *cli.Context) *config.DockerClient { config := &config.DockerClient{ - UseTLS: ctx.GlobalBool(FlagUseTLS), - VerifyTLS: ctx.GlobalBool(FlagVerifyTLS), - TLSCertPath: ctx.GlobalString(FlagTLSCertPath), - Host: ctx.GlobalString(FlagHost), + UseTLS: ctx.Bool(FlagUseTLS), + VerifyTLS: ctx.Bool(FlagVerifyTLS), + TLSCertPath: ctx.String(FlagTLSCertPath), + Host: ctx.String(FlagHost), Env: map[string]string{}, } diff --git a/pkg/app/master/commands/cliprompt.go b/pkg/app/master/commands/cliprompt.go index ad2eb6fa01..402797c2f9 100644 --- a/pkg/app/master/commands/cliprompt.go +++ b/pkg/app/master/commands/cliprompt.go @@ -15,7 +15,7 @@ import ( dockerapi "github.com/fsouza/go-dockerclient" "github.com/google/shlex" log "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" "github.com/docker-slim/docker-slim/pkg/app" "github.com/docker-slim/docker-slim/pkg/app/master/config" diff --git a/pkg/app/master/commands/common.go b/pkg/app/master/commands/common.go index c6abe2a8f7..7cab6bd8be 100644 --- a/pkg/app/master/commands/common.go +++ b/pkg/app/master/commands/common.go @@ -5,7 +5,7 @@ import ( docker "github.com/fsouza/go-dockerclient" log "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" "github.com/docker-slim/docker-slim/pkg/app/master/config" "github.com/docker-slim/docker-slim/pkg/docker/dockerutil" @@ -136,4 +136,4 @@ func ConfirmNetwork(logger *log.Entry, client *docker.Client, network string) bo return false } -var CLI []cli.Command +var CLI []*cli.Command diff --git a/pkg/app/master/commands/containerize/cli.go b/pkg/app/master/commands/containerize/cli.go index a74eb5029f..5d6d73c5af 100644 --- a/pkg/app/master/commands/containerize/cli.go +++ b/pkg/app/master/commands/containerize/cli.go @@ -3,7 +3,7 @@ package containerize import ( "fmt" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" "github.com/docker-slim/docker-slim/pkg/app" "github.com/docker-slim/docker-slim/pkg/app/master/commands" @@ -15,12 +15,12 @@ const ( Alias = "c" ) -var CLI = cli.Command{ +var CLI = &cli.Command{ Name: Name, Aliases: []string{Alias}, Usage: Usage, Action: func(ctx *cli.Context) error { - if len(ctx.Args()) < 1 { + if ctx.Args().Len() < 1 { fmt.Printf("docker-slim[%s]: missing target info...\n\n", Name) cli.ShowCommandHelp(ctx, Name) return nil diff --git a/pkg/app/master/commands/convert/cli.go b/pkg/app/master/commands/convert/cli.go index 1aa14f0305..8f0c0163a6 100644 --- a/pkg/app/master/commands/convert/cli.go +++ b/pkg/app/master/commands/convert/cli.go @@ -3,7 +3,7 @@ package convert import ( "fmt" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" "github.com/docker-slim/docker-slim/pkg/app" "github.com/docker-slim/docker-slim/pkg/app/master/commands" @@ -15,12 +15,12 @@ const ( Alias = "k" ) -var CLI = cli.Command{ +var CLI = &cli.Command{ Name: Name, Aliases: []string{Alias}, Usage: Usage, Action: func(ctx *cli.Context) error { - if len(ctx.Args()) < 1 { + if ctx.Args().Len() < 1 { fmt.Printf("docker-slim[%s]: missing target info...\n\n", Name) cli.ShowCommandHelp(ctx, Name) return nil diff --git a/pkg/app/master/commands/debug/cli.go b/pkg/app/master/commands/debug/cli.go index 5e515f40eb..f01d23af5b 100644 --- a/pkg/app/master/commands/debug/cli.go +++ b/pkg/app/master/commands/debug/cli.go @@ -3,7 +3,7 @@ package debug import ( "fmt" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" "github.com/docker-slim/docker-slim/pkg/app" "github.com/docker-slim/docker-slim/pkg/app/master/commands" @@ -17,12 +17,12 @@ const ( Alias = "dbg" ) -var CLI = cli.Command{ +var CLI = &cli.Command{ Name: Name, Aliases: []string{Alias}, Usage: Usage, Action: func(ctx *cli.Context) error { - if len(ctx.Args()) < 1 { + if ctx.Args().Len() < 1 { fmt.Printf("docker-slim[%s]: missing target info...\n\n", Name) cli.ShowCommandHelp(ctx, Name) return nil diff --git a/pkg/app/master/commands/dockerclipm/cli.go b/pkg/app/master/commands/dockerclipm/cli.go index ccb400dc6d..a60b7b9da1 100644 --- a/pkg/app/master/commands/dockerclipm/cli.go +++ b/pkg/app/master/commands/dockerclipm/cli.go @@ -4,7 +4,7 @@ import ( "encoding/json" "os" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" "github.com/docker-slim/docker-slim/pkg/version" ) @@ -22,7 +22,7 @@ type pluginMetadata struct { URL string } -var CLI = cli.Command{ +var CLI = &cli.Command{ Category: "internal.metadata", Name: Name, Usage: Usage, diff --git a/pkg/app/master/commands/edit/cli.go b/pkg/app/master/commands/edit/cli.go index d491a575a8..818bf9232e 100644 --- a/pkg/app/master/commands/edit/cli.go +++ b/pkg/app/master/commands/edit/cli.go @@ -3,7 +3,7 @@ package edit import ( "fmt" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" "github.com/docker-slim/docker-slim/pkg/app" "github.com/docker-slim/docker-slim/pkg/app/master/commands" @@ -15,12 +15,12 @@ const ( Alias = "e" ) -var CLI = cli.Command{ +var CLI = &cli.Command{ Name: Name, Aliases: []string{Alias}, Usage: Usage, Action: func(ctx *cli.Context) error { - if len(ctx.Args()) < 1 { + if ctx.Args().Len() < 1 { fmt.Printf("docker-slim[%s]: missing target info...\n\n", Name) cli.ShowCommandHelp(ctx, Name) return nil diff --git a/pkg/app/master/commands/help/cli.go b/pkg/app/master/commands/help/cli.go index e4e2f6e776..7bc8347871 100644 --- a/pkg/app/master/commands/help/cli.go +++ b/pkg/app/master/commands/help/cli.go @@ -1,7 +1,7 @@ package help import ( - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) const ( @@ -10,7 +10,7 @@ const ( Alias = "h" ) -var CLI = cli.Command{ +var CLI = &cli.Command{ Name: Name, Aliases: []string{Alias}, Usage: Usage, diff --git a/pkg/app/master/commands/install/cli.go b/pkg/app/master/commands/install/cli.go index 5938cabf2d..4b4cf479bf 100644 --- a/pkg/app/master/commands/install/cli.go +++ b/pkg/app/master/commands/install/cli.go @@ -3,7 +3,7 @@ package install import ( "github.com/docker-slim/docker-slim/pkg/app/master/commands" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) const ( @@ -17,22 +17,22 @@ const ( FlagDockerCLIPluginUsage = "Install as Docker CLI plugin" ) -var CLI = cli.Command{ +var CLI = &cli.Command{ Name: Name, Aliases: []string{Alias}, Usage: Usage, Flags: []cli.Flag{ - cli.BoolFlag{ - Name: FlagDockerCLIPlugin, - Usage: FlagDockerCLIPluginUsage, - EnvVar: "DSLIM_INSTALL_DOCKER_CLI_PLUGIN", + &cli.BoolFlag{ + Name: FlagDockerCLIPlugin, + Usage: FlagDockerCLIPluginUsage, + EnvVars: []string{"DSLIM_INSTALL_DOCKER_CLI_PLUGIN"}, }, }, Action: func(ctx *cli.Context) error { - doDebug := ctx.GlobalBool(commands.FlagDebug) - statePath := ctx.GlobalString(commands.FlagStatePath) - inContainer, isDSImage := commands.IsInContainer(ctx.GlobalBool(commands.FlagInContainer)) - archiveState := commands.ArchiveState(ctx.GlobalString(commands.FlagArchiveState), inContainer) + doDebug := ctx.Bool(commands.FlagDebug) + statePath := ctx.String(commands.FlagStatePath) + inContainer, isDSImage := commands.IsInContainer(ctx.Bool(commands.FlagInContainer)) + archiveState := commands.ArchiveState(ctx.String(commands.FlagArchiveState), inContainer) dockerCLIPlugin := ctx.Bool(FlagDockerCLIPlugin) OnCommand(doDebug, statePath, archiveState, inContainer, isDSImage, dockerCLIPlugin) diff --git a/pkg/app/master/commands/lint/cli.go b/pkg/app/master/commands/lint/cli.go index 48f06fd14a..0ec8d68cb4 100644 --- a/pkg/app/master/commands/lint/cli.go +++ b/pkg/app/master/commands/lint/cli.go @@ -1,7 +1,7 @@ package lint import ( - "github.com/urfave/cli" + "github.com/urfave/cli/v2" "github.com/docker-slim/docker-slim/pkg/app" "github.com/docker-slim/docker-slim/pkg/app/master/commands" @@ -13,7 +13,7 @@ const ( Alias = "l" ) -var CLI = cli.Command{ +var CLI = &cli.Command{ Name: Name, Aliases: []string{Alias}, Usage: Usage, @@ -41,7 +41,7 @@ var CLI = cli.Command{ targetRef := ctx.String(commands.FlagTarget) if !doListChecks { if targetRef == "" { - if len(ctx.Args()) < 1 { + if ctx.Args().Len() < 1 { xc.Out.Error("param.target", "missing target Dockerfile") cli.ShowCommandHelp(ctx, Name) return nil diff --git a/pkg/app/master/commands/lint/flags.go b/pkg/app/master/commands/lint/flags.go index 9f3481e14d..bff28db6dc 100644 --- a/pkg/app/master/commands/lint/flags.go +++ b/pkg/app/master/commands/lint/flags.go @@ -4,7 +4,7 @@ import ( "github.com/docker-slim/docker-slim/pkg/app/master/commands" log "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // Lint command flag names @@ -43,84 +43,85 @@ const ( ) var Flags = map[string]cli.Flag{ - commands.FlagTarget: cli.StringFlag{ - Name: commands.FlagTarget, - Value: "", - Usage: FlagLintTargetUsage, - EnvVar: "DSLIM_TARGET", + commands.FlagTarget: &cli.StringFlag{ + Name: commands.FlagTarget, + Value: "", + Usage: FlagLintTargetUsage, + EnvVars: []string{"DSLIM_TARGET"}, }, - FlagTargetType: cli.StringFlag{ - Name: FlagTargetType, - Value: "", - Usage: FlagTargetTypeUsage, - EnvVar: "DSLIM_LINT_TARGET_TYPE", + FlagTargetType: &cli.StringFlag{ + Name: FlagTargetType, + Value: "", + Usage: FlagTargetTypeUsage, + EnvVars: []string{"DSLIM_LINT_TARGET_TYPE"}, }, - FlagSkipBuildContext: cli.BoolFlag{ - Name: FlagSkipBuildContext, - Usage: FlagSkipBuildContextUsage, - EnvVar: "DSLIM_LINT_SKIP_BC", + FlagSkipBuildContext: &cli.BoolFlag{ + Name: FlagSkipBuildContext, + Usage: FlagSkipBuildContextUsage, + EnvVars: []string{"DSLIM_LINT_SKIP_BC"}, }, - FlagBuildContextDir: cli.StringFlag{ - Name: FlagBuildContextDir, - Value: "", - Usage: FlagBuildContextDirUsage, - EnvVar: "DSLIM_LINT_BC_DIR", + FlagBuildContextDir: &cli.StringFlag{ + Name: FlagBuildContextDir, + Value: "", + Usage: FlagBuildContextDirUsage, + EnvVars: []string{"DSLIM_LINT_BC_DIR"}, }, - FlagSkipDockerignore: cli.BoolFlag{ - Name: FlagSkipDockerignore, - Usage: FlagSkipDockerignoreUsage, - EnvVar: "DSLIM_LINT_SKIP_DI", + FlagSkipDockerignore: &cli.BoolFlag{ + Name: FlagSkipDockerignore, + Usage: FlagSkipDockerignoreUsage, + EnvVars: []string{"DSLIM_LINT_SKIP_DI"}, }, - FlagIncludeCheckLabel: cli.StringSliceFlag{ - Name: FlagIncludeCheckLabel, - Value: &cli.StringSlice{""}, - Usage: FlagIncludeCheckLabelUsage, - EnvVar: "DSLIM_LINT_INCLUDE_LABEL", + FlagIncludeCheckLabel: &cli.StringSliceFlag{ + Name: FlagIncludeCheckLabel, + Value: cli.NewStringSlice(""), + Usage: FlagIncludeCheckLabelUsage, + EnvVars: []string{"DSLIM_LINT_INCLUDE_LABEL"}, }, - FlagExcludeCheckLabel: cli.StringSliceFlag{ - Name: FlagExcludeCheckLabel, - Value: &cli.StringSlice{""}, - Usage: FlagExcludeCheckLabelUsage, - EnvVar: "DSLIM_LINT_EXCLUDE_LABEL", + FlagExcludeCheckLabel: &cli.StringSliceFlag{ + Name: FlagExcludeCheckLabel, + Value: cli.NewStringSlice(""), + Usage: FlagExcludeCheckLabelUsage, + EnvVars: []string{"DSLIM_LINT_EXCLUDE_LABEL"}, }, - FlagIncludeCheckID: cli.StringSliceFlag{ - Name: FlagIncludeCheckID, - Value: &cli.StringSlice{""}, - Usage: FlagIncludeCheckIDUsage, - EnvVar: "DSLIM_LINT_INCLUDE_CID", + FlagIncludeCheckID: &cli.StringSliceFlag{ + Name: FlagIncludeCheckID, + Value: cli.NewStringSlice(""), + Usage: FlagIncludeCheckIDUsage, + EnvVars: []string{"DSLIM_LINT_INCLUDE_CID"}, }, - FlagIncludeCheckIDFile: cli.StringFlag{ - Name: FlagIncludeCheckIDFile, - Value: "", - Usage: FlagIncludeCheckIDFileUsage, - EnvVar: "DSLIM_LINT_INCLUDE_CID_FILE", + FlagIncludeCheckIDFile: &cli.StringFlag{ + Name: FlagIncludeCheckIDFile, + Value: "", + Usage: FlagIncludeCheckIDFileUsage, + EnvVars: []string{"DSLIM_LINT_INCLUDE_CID_FILE"}, }, - FlagExcludeCheckID: cli.StringSliceFlag{ - Name: FlagExcludeCheckID, - Value: &cli.StringSlice{""}, - Usage: FlagExcludeCheckIDUsage, - EnvVar: "DSLIM_LINT_EXCLUDE_CID", + FlagExcludeCheckID: &cli.StringSliceFlag{ + Name: FlagExcludeCheckID, + Value: cli.NewStringSlice(""), + Usage: FlagExcludeCheckIDUsage, + EnvVars: []string{"DSLIM_LINT_EXCLUDE_CID"}, }, - FlagExcludeCheckIDFile: cli.StringFlag{ - Name: FlagExcludeCheckIDFile, - Value: "", - Usage: FlagExcludeCheckIDFileUsage, - EnvVar: "DSLIM_LINT_EXCLUDE_CID_FILE", + FlagExcludeCheckIDFile: &cli.StringFlag{ + Name: FlagExcludeCheckIDFile, + Value: "", + Usage: FlagExcludeCheckIDFileUsage, + EnvVars: []string{"DSLIM_LINT_EXCLUDE_CID_FILE"}, }, - FlagShowNoHits: cli.BoolFlag{ - Name: FlagShowNoHits, - Usage: FlagShowNoHitsUsage, - EnvVar: "DSLIM_LINT_SHOW_NOHITS", + FlagShowNoHits: &cli.BoolFlag{ + Name: FlagShowNoHits, + Usage: FlagShowNoHitsUsage, + EnvVars: []string{"DSLIM_LINT_SHOW_NOHITS"}, }, - FlagShowSnippet: cli.BoolTFlag{ - Name: FlagShowSnippet, - Usage: FlagShowSnippetUsage, - EnvVar: "DSLIM_LINT_SHOW_SNIPPET", + FlagShowSnippet: &cli.BoolFlag{ + Name: FlagShowSnippet, + Value: true, + Usage: FlagShowSnippetUsage, + EnvVars: []string{"DSLIM_LINT_SHOW_SNIPPET"}, }, - FlagListChecks: cli.BoolFlag{ - Name: FlagListChecks, - Usage: FlagListChecksUsage, - EnvVar: "DSLIM_LINT_LIST_CHECKS", + FlagListChecks: &cli.BoolFlag{ + Name: FlagListChecks, + Usage: FlagListChecksUsage, + EnvVars: []string{"DSLIM_LINT_LIST_CHECKS"}, }, } diff --git a/pkg/app/master/commands/probe/cli.go b/pkg/app/master/commands/probe/cli.go index 4abdaf3c83..2d69524ef1 100644 --- a/pkg/app/master/commands/probe/cli.go +++ b/pkg/app/master/commands/probe/cli.go @@ -6,7 +6,7 @@ import ( "github.com/docker-slim/docker-slim/pkg/app" "github.com/docker-slim/docker-slim/pkg/app/master/commands" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) //Standalone probing @@ -17,12 +17,12 @@ const ( Alias = "prb" ) -var CLI = cli.Command{ +var CLI = &cli.Command{ Name: Name, Aliases: []string{Alias}, Usage: Usage, Action: func(ctx *cli.Context) error { - if len(ctx.Args()) < 1 { + if ctx.Args().Len() < 1 { fmt.Printf("docker-slim[%s]: missing target info...\n\n", Name) cli.ShowCommandHelp(ctx, Name) return nil diff --git a/pkg/app/master/commands/profile/cli.go b/pkg/app/master/commands/profile/cli.go index 45338eab45..78111e0ae5 100644 --- a/pkg/app/master/commands/profile/cli.go +++ b/pkg/app/master/commands/profile/cli.go @@ -7,7 +7,7 @@ import ( "github.com/docker-slim/docker-slim/pkg/app/master/commands" "github.com/docker-slim/docker-slim/pkg/app/master/config" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) const ( @@ -16,7 +16,7 @@ const ( Alias = "p" ) -var CLI = cli.Command{ +var CLI = &cli.Command{ Name: Name, Aliases: []string{Alias}, Usage: Usage, @@ -109,7 +109,7 @@ var CLI = cli.Command{ targetRef := ctx.String(commands.FlagTarget) if targetRef == "" { - if len(ctx.Args()) < 1 { + if ctx.Args().Len() < 1 { xc.Out.Error("param.target", "missing target image ID/name") cli.ShowCommandHelp(ctx, Name) return nil @@ -326,7 +326,7 @@ var CLI = cli.Command{ //doKeepTmpArtifacts := ctx.Bool(commands.FlagKeepTmpArtifacts) - doExcludeMounts := ctx.BoolT(commands.FlagExcludeMounts) + doExcludeMounts := ctx.Bool(commands.FlagExcludeMounts) if doExcludeMounts { for mpath := range volumeMounts { excludePatterns[mpath] = nil @@ -353,7 +353,7 @@ var CLI = cli.Command{ }) } - commandReport := ctx.GlobalString(commands.FlagCommandReport) + commandReport := ctx.String(commands.FlagCommandReport) if commandReport == "off" { commandReport = "" } @@ -406,8 +406,8 @@ var CLI = cli.Command{ doUseSensorVolume, //doKeepTmpArtifacts, continueAfter, - ctx.GlobalString(commands.FlagLogLevel), - ctx.GlobalString(commands.FlagLogFormat)) + ctx.String(commands.FlagLogLevel), + ctx.String(commands.FlagLogFormat)) return nil }, diff --git a/pkg/app/master/commands/run/cli.go b/pkg/app/master/commands/run/cli.go index 2b41ebafe1..eb5a21851e 100644 --- a/pkg/app/master/commands/run/cli.go +++ b/pkg/app/master/commands/run/cli.go @@ -6,7 +6,7 @@ import ( "github.com/docker-slim/docker-slim/pkg/app/master/config" dockerapi "github.com/fsouza/go-dockerclient" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) const ( @@ -77,7 +77,7 @@ func CommandFlagValues(ctx *cli.Context) (*CommandParams, error) { return values, nil } -var CLI = cli.Command{ +var CLI = &cli.Command{ Name: Name, Aliases: []string{Alias}, Usage: Usage, @@ -112,7 +112,7 @@ var CLI = cli.Command{ } if cparams.TargetRef == "" { - if len(ctx.Args()) < 1 { + if ctx.Args().Len() < 1 { xc.Out.Error("param.target", "missing target") cli.ShowCommandHelp(ctx, Name) return nil diff --git a/pkg/app/master/commands/run/flags.go b/pkg/app/master/commands/run/flags.go index 6d72cf3118..6520104bbb 100644 --- a/pkg/app/master/commands/run/flags.go +++ b/pkg/app/master/commands/run/flags.go @@ -2,7 +2,7 @@ package run import ( log "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // Run command flag names @@ -24,31 +24,31 @@ const ( ) var Flags = map[string]cli.Flag{ - FlagLiveLogs: cli.BoolFlag{ - Name: FlagLiveLogs, - Usage: FlagLiveLogsUsage, - EnvVar: "DSLIM_RUN_LIVE_LOGS", + FlagLiveLogs: &cli.BoolFlag{ + Name: FlagLiveLogs, + Usage: FlagLiveLogsUsage, + EnvVars: []string{"DSLIM_RUN_LIVE_LOGS"}, }, - FlagTerminal: cli.BoolFlag{ - Name: FlagTerminal, - Usage: FlagTerminalUsage, - EnvVar: "DSLIM_RUN_TERMINAL", + FlagTerminal: &cli.BoolFlag{ + Name: FlagTerminal, + Usage: FlagTerminalUsage, + EnvVars: []string{"DSLIM_RUN_TERMINAL"}, }, - FlagPublishPort: cli.StringSliceFlag{ - Name: FlagPublishPort, - Value: &cli.StringSlice{}, - Usage: FlagPublishPortUsage, - EnvVar: "DSLIM_RUN_PUBLISH_PORT", + FlagPublishPort: &cli.StringSliceFlag{ + Name: FlagPublishPort, + Value: &cli.StringSlice{}, + Usage: FlagPublishPortUsage, + EnvVars: []string{"DSLIM_RUN_PUBLISH_PORT"}, }, - FlagRemove: cli.BoolFlag{ - Name: FlagRemove, - Usage: FlagRemoveUsage, - EnvVar: "DSLIM_RUN_RM", + FlagRemove: &cli.BoolFlag{ + Name: FlagRemove, + Usage: FlagRemoveUsage, + EnvVars: []string{"DSLIM_RUN_RM"}, }, - FlagDetach: cli.BoolFlag{ - Name: FlagDetach, - Usage: FlagDetachUsage, - EnvVar: "DSLIM_RUN_DETACH", + FlagDetach: &cli.BoolFlag{ + Name: FlagDetach, + Usage: FlagDetachUsage, + EnvVars: []string{"DSLIM_RUN_DETACH"}, }, } diff --git a/pkg/app/master/commands/server/cli.go b/pkg/app/master/commands/server/cli.go index 06c746440c..fae3debcf9 100644 --- a/pkg/app/master/commands/server/cli.go +++ b/pkg/app/master/commands/server/cli.go @@ -4,7 +4,7 @@ import ( "github.com/docker-slim/docker-slim/pkg/app" "github.com/docker-slim/docker-slim/pkg/app/master/commands" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) const ( @@ -13,7 +13,7 @@ const ( Alias = "s" ) -var CLI = cli.Command{ +var CLI = &cli.Command{ Name: Name, Aliases: []string{Alias}, Usage: Usage, diff --git a/pkg/app/master/commands/update/cli.go b/pkg/app/master/commands/update/cli.go index 553dd86b31..7de305ff79 100644 --- a/pkg/app/master/commands/update/cli.go +++ b/pkg/app/master/commands/update/cli.go @@ -6,7 +6,7 @@ import ( "github.com/docker-slim/docker-slim/pkg/app/master/commands" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) const ( @@ -15,7 +15,7 @@ const ( Alias = "u" ) -var CLI = cli.Command{ +var CLI = &cli.Command{ Name: Name, Aliases: []string{Alias}, Usage: Usage, @@ -23,10 +23,10 @@ var CLI = cli.Command{ initFlagShowProgress(), }, Action: func(ctx *cli.Context) error { - doDebug := ctx.GlobalBool(commands.FlagDebug) - statePath := ctx.GlobalString(commands.FlagStatePath) - inContainer, isDSImage := commands.IsInContainer(ctx.GlobalBool(commands.FlagInContainer)) - archiveState := commands.ArchiveState(ctx.GlobalString(commands.FlagArchiveState), inContainer) + doDebug := ctx.Bool(commands.FlagDebug) + statePath := ctx.String(commands.FlagStatePath) + inContainer, isDSImage := commands.IsInContainer(ctx.Bool(commands.FlagInContainer)) + archiveState := commands.ArchiveState(ctx.String(commands.FlagArchiveState), inContainer) doShowProgress := ctx.Bool(commands.FlagShowProgress) OnCommand(doDebug, statePath, archiveState, inContainer, isDSImage, doShowProgress) @@ -39,16 +39,17 @@ func initFlagShowProgress() cli.Flag { var doShowProgressFlag cli.Flag switch runtime.GOOS { case "darwin": - doShowProgressFlag = cli.BoolTFlag{ - Name: commands.FlagShowProgress, - Usage: fmt.Sprintf("%s (default: true)", commands.FlagShowProgressUsage), - EnvVar: "DSLIM_UPDATE_SHOW_PROGRESS", + doShowProgressFlag = &cli.BoolFlag{ + Name: commands.FlagShowProgress, + Value: true, + Usage: fmt.Sprintf("%s (default: true)", commands.FlagShowProgressUsage), + EnvVars: []string{"DSLIM_UPDATE_SHOW_PROGRESS"}, } default: - doShowProgressFlag = cli.BoolFlag{ - Name: commands.FlagShowProgress, - Usage: fmt.Sprintf("%s (default: false)", commands.FlagShowProgressUsage), - EnvVar: "DSLIM_UPDATE_SHOW_PROGRESS", + doShowProgressFlag = &cli.BoolFlag{ + Name: commands.FlagShowProgress, + Usage: fmt.Sprintf("%s (default: false)", commands.FlagShowProgressUsage), + EnvVars: []string{"DSLIM_UPDATE_SHOW_PROGRESS"}, } } diff --git a/pkg/app/master/commands/version/cli.go b/pkg/app/master/commands/version/cli.go index fcc80c9cbe..5772f247b3 100644 --- a/pkg/app/master/commands/version/cli.go +++ b/pkg/app/master/commands/version/cli.go @@ -4,7 +4,7 @@ import ( "github.com/docker-slim/docker-slim/pkg/app" "github.com/docker-slim/docker-slim/pkg/app/master/commands" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) const ( @@ -13,13 +13,13 @@ const ( Alias = "v" ) -var CLI = cli.Command{ +var CLI = &cli.Command{ Name: Name, Aliases: []string{Alias}, Usage: Usage, Action: func(ctx *cli.Context) error { - doDebug := ctx.GlobalBool(commands.FlagDebug) - inContainer, isDSImage := commands.IsInContainer(ctx.GlobalBool(commands.FlagInContainer)) + doDebug := ctx.Bool(commands.FlagDebug) + inContainer, isDSImage := commands.IsInContainer(ctx.Bool(commands.FlagInContainer)) clientConfig := commands.GetDockerClientConfig(ctx) xc := app.NewExecutionContext(Name) diff --git a/pkg/app/master/commands/xray/cli.go b/pkg/app/master/commands/xray/cli.go index ce55b3706a..a60b3cce00 100644 --- a/pkg/app/master/commands/xray/cli.go +++ b/pkg/app/master/commands/xray/cli.go @@ -9,7 +9,7 @@ import ( "github.com/docker-slim/docker-slim/pkg/app/master/commands" "github.com/docker-slim/docker-slim/pkg/docker/dockerimage" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) const ( @@ -18,7 +18,7 @@ const ( Alias = "x" ) -var CLI = cli.Command{ +var CLI = &cli.Command{ Name: Name, Aliases: []string{Alias}, Usage: Usage, @@ -61,7 +61,7 @@ var CLI = cli.Command{ targetRef := ctx.String(commands.FlagTarget) if targetRef == "" { - if len(ctx.Args()) < 1 { + if ctx.Args().Len() < 1 { xc.Out.Error("param.target", "missing image ID/name") cli.ShowCommandHelp(ctx, Name) return nil diff --git a/pkg/app/master/commands/xray/flags.go b/pkg/app/master/commands/xray/flags.go index f4d3db7b1a..51a84993f3 100644 --- a/pkg/app/master/commands/xray/flags.go +++ b/pkg/app/master/commands/xray/flags.go @@ -2,7 +2,7 @@ package xray import ( log "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // Xray command flag names @@ -62,137 +62,140 @@ const ( ) var Flags = map[string]cli.Flag{ - FlagChanges: cli.StringSliceFlag{ - Name: FlagChanges, - Value: &cli.StringSlice{""}, - Usage: FlagChangesUsage, - EnvVar: "DSLIM_CHANGES", - }, - FlagChangesOutput: cli.StringSliceFlag{ - Name: FlagChangesOutput, - Value: &cli.StringSlice{"all"}, - Usage: FlagChangesOutputUsage, - EnvVar: "DSLIM_CHANGES_OUTPUT", - }, - FlagLayer: cli.StringSliceFlag{ - Name: FlagLayer, - Value: &cli.StringSlice{}, - Usage: FlagLayerUsage, - EnvVar: "DSLIM_LAYER", - }, - FlagAddImageManifest: cli.BoolFlag{ - Name: FlagAddImageManifest, - Usage: FlagAddImageManifestUsage, - EnvVar: "DSLIM_XRAY_IMAGE_MANIFEST", - }, - FlagAddImageConfig: cli.BoolFlag{ - Name: FlagAddImageConfig, - Usage: FlagAddImageConfigUsage, - EnvVar: "DSLIM_XRAY_IMAGE_CONFIG", - }, - FlagLayerChangesMax: cli.IntFlag{ - Name: FlagLayerChangesMax, - Value: -1, - Usage: FlagLayerChangesMaxUsage, - EnvVar: "DSLIM_XRAY_LAYER_CHANGES_MAX", - }, - FlagAllChangesMax: cli.IntFlag{ - Name: FlagAllChangesMax, - Value: -1, - Usage: FlagAllChangesMaxUsage, - EnvVar: "DSLIM_XRAY_ALL_CHANGES_MAX", - }, - FlagAddChangesMax: cli.IntFlag{ - Name: FlagAddChangesMax, - Value: -1, - Usage: FlagAddChangesMaxUsage, - EnvVar: "DSLIM_XRAY_ADD_CHANGES_MAX", - }, - FlagModifyChangesMax: cli.IntFlag{ - Name: FlagModifyChangesMax, - Value: -1, - Usage: FlagModifyChangesMaxUsage, - EnvVar: "DSLIM_XRAY_MODIFY_CHANGES_MAX", - }, - FlagDeleteChangesMax: cli.IntFlag{ - Name: FlagDeleteChangesMax, - Value: -1, - Usage: FlagDeleteChangesMaxUsage, - EnvVar: "DSLIM_XRAY_DELETE_CHANGES_MAX", - }, - FlagChangePath: cli.StringSliceFlag{ - Name: FlagChangePath, - Value: &cli.StringSlice{}, - Usage: FlagChangePathUsage, - EnvVar: "DSLIM_XRAY_CHANGE_PATH", - }, - FlagChangeData: cli.StringSliceFlag{ - Name: FlagChangeData, - Value: &cli.StringSlice{}, - Usage: FlagChangeDataUsage, - EnvVar: "DSLIM_XRAY_CHANGE_DATA", - }, - FlagReuseSavedImage: cli.BoolTFlag{ - Name: FlagReuseSavedImage, - Usage: FlagReuseSavedImageUsage, - EnvVar: "DSLIM_XRAY_REUSE_SAVED", - }, - FlagTopChangesMax: cli.IntFlag{ - Name: FlagTopChangesMax, - Value: 20, - Usage: FlagTopChangesMaxUsage, - EnvVar: "DSLIM_XRAY_TOP_CHANGES_MAX", - }, - FlagHashData: cli.BoolFlag{ - Name: FlagHashData, - Usage: FlagHashDataUsage, - EnvVar: "DSLIM_XRAY_HASH_DATA", - }, - FlagDetectUTF8: cli.StringFlag{ - Name: FlagDetectUTF8, - Usage: FlagDetectUTF8Usage, - EnvVar: "DSLIM_XRAY_DETECT_UTF8", - }, - FlagDetectDuplicates: cli.BoolTFlag{ - Name: FlagDetectDuplicates, - Usage: FlagDetectDuplicatesUsage, - EnvVar: "DSLIM_XRAY_DETECT_DUP", - }, - FlagShowDuplicates: cli.BoolFlag{ - Name: FlagShowDuplicates, - Usage: FlagShowDuplicatesUsage, - EnvVar: "DSLIM_XRAY_SHOW_DUP", - }, - FlagShowSpecialPerms: cli.BoolTFlag{ - Name: FlagShowSpecialPerms, - Usage: FlagShowSpecialPermsUsage, - EnvVar: "DSLIM_XRAY_SHOW_SPECIAL", - }, - FlagChangeDataHash: cli.StringSliceFlag{ - Name: FlagChangeDataHash, - Value: &cli.StringSlice{}, - Usage: FlagChangeDataHashUsage, - EnvVar: "DSLIM_XRAY_CHANGE_DATA_HASH", - }, - FlagChangeMatchLayersOnly: cli.BoolFlag{ - Name: FlagChangeMatchLayersOnly, - Usage: FlagChangeMatchLayersOnlyUsage, - EnvVar: "DSLIM_XRAY_CHANGE_MATCH_LAYERS_ONLY", - }, - FlagExportAllDataArtifacts: cli.StringFlag{ - Name: FlagExportAllDataArtifacts, - Usage: FlagExportAllDataArtifactsUsage, - EnvVar: "DSLIM_XRAY_EXPORT_ALL_DARTIFACTS", - }, - FlagDetectAllCertFiles: cli.BoolFlag{ - Name: FlagDetectAllCertFiles, - Usage: FlagDetectAllCertFilesUsage, - EnvVar: "DSLIM_XRAY_DETECT_ALL_CERTS", - }, - FlagDetectAllCertPKFiles: cli.BoolFlag{ - Name: FlagDetectAllCertPKFiles, - Usage: FlagDetectAllCertPKFilesUsage, - EnvVar: "DSLIM_XRAY_DETECT_ALL_CERT_PKS", + FlagChanges: &cli.StringSliceFlag{ + Name: FlagChanges, + Value: cli.NewStringSlice(""), + Usage: FlagChangesUsage, + EnvVars: []string{"DSLIM_CHANGES"}, + }, + FlagChangesOutput: &cli.StringSliceFlag{ + Name: FlagChangesOutput, + Value: cli.NewStringSlice("all"), + Usage: FlagChangesOutputUsage, + EnvVars: []string{"DSLIM_CHANGES_OUTPUT"}, + }, + FlagLayer: &cli.StringSliceFlag{ + Name: FlagLayer, + Value: cli.NewStringSlice(), + Usage: FlagLayerUsage, + EnvVars: []string{"DSLIM_LAYER"}, + }, + FlagAddImageManifest: &cli.BoolFlag{ + Name: FlagAddImageManifest, + Usage: FlagAddImageManifestUsage, + EnvVars: []string{"DSLIM_XRAY_IMAGE_MANIFEST"}, + }, + FlagAddImageConfig: &cli.BoolFlag{ + Name: FlagAddImageConfig, + Usage: FlagAddImageConfigUsage, + EnvVars: []string{"DSLIM_XRAY_IMAGE_CONFIG"}, + }, + FlagLayerChangesMax: &cli.IntFlag{ + Name: FlagLayerChangesMax, + Value: -1, + Usage: FlagLayerChangesMaxUsage, + EnvVars: []string{"DSLIM_XRAY_LAYER_CHANGES_MAX"}, + }, + FlagAllChangesMax: &cli.IntFlag{ + Name: FlagAllChangesMax, + Value: -1, + Usage: FlagAllChangesMaxUsage, + EnvVars: []string{"DSLIM_XRAY_ALL_CHANGES_MAX"}, + }, + FlagAddChangesMax: &cli.IntFlag{ + Name: FlagAddChangesMax, + Value: -1, + Usage: FlagAddChangesMaxUsage, + EnvVars: []string{"DSLIM_XRAY_ADD_CHANGES_MAX"}, + }, + FlagModifyChangesMax: &cli.IntFlag{ + Name: FlagModifyChangesMax, + Value: -1, + Usage: FlagModifyChangesMaxUsage, + EnvVars: []string{"DSLIM_XRAY_MODIFY_CHANGES_MAX"}, + }, + FlagDeleteChangesMax: &cli.IntFlag{ + Name: FlagDeleteChangesMax, + Value: -1, + Usage: FlagDeleteChangesMaxUsage, + EnvVars: []string{"DSLIM_XRAY_DELETE_CHANGES_MAX"}, + }, + FlagChangePath: &cli.StringSliceFlag{ + Name: FlagChangePath, + Value: cli.NewStringSlice(), + Usage: FlagChangePathUsage, + EnvVars: []string{"DSLIM_XRAY_CHANGE_PATH"}, + }, + FlagChangeData: &cli.StringSliceFlag{ + Name: FlagChangeData, + Value: cli.NewStringSlice(), + Usage: FlagChangeDataUsage, + EnvVars: []string{"DSLIM_XRAY_CHANGE_DATA"}, + }, + FlagReuseSavedImage: &cli.BoolFlag{ + Name: FlagReuseSavedImage, + Value: true, + Usage: FlagReuseSavedImageUsage, + EnvVars: []string{"DSLIM_XRAY_REUSE_SAVED"}, + }, + FlagTopChangesMax: &cli.IntFlag{ + Name: FlagTopChangesMax, + Value: 20, + Usage: FlagTopChangesMaxUsage, + EnvVars: []string{"DSLIM_XRAY_TOP_CHANGES_MAX"}, + }, + FlagHashData: &cli.BoolFlag{ + Name: FlagHashData, + Usage: FlagHashDataUsage, + EnvVars: []string{"DSLIM_XRAY_HASH_DATA"}, + }, + FlagDetectUTF8: &cli.StringFlag{ + Name: FlagDetectUTF8, + Usage: FlagDetectUTF8Usage, + EnvVars: []string{"DSLIM_XRAY_DETECT_UTF8"}, + }, + FlagDetectDuplicates: &cli.BoolFlag{ + Name: FlagDetectDuplicates, + Value: true, + Usage: FlagDetectDuplicatesUsage, + EnvVars: []string{"DSLIM_XRAY_DETECT_DUP"}, + }, + FlagShowDuplicates: &cli.BoolFlag{ + Name: FlagShowDuplicates, + Usage: FlagShowDuplicatesUsage, + EnvVars: []string{"DSLIM_XRAY_SHOW_DUP"}, + }, + FlagShowSpecialPerms: &cli.BoolFlag{ + Name: FlagShowSpecialPerms, + Value: true, + Usage: FlagShowSpecialPermsUsage, + EnvVars: []string{"DSLIM_XRAY_SHOW_SPECIAL"}, + }, + FlagChangeDataHash: &cli.StringSliceFlag{ + Name: FlagChangeDataHash, + Value: cli.NewStringSlice(), + Usage: FlagChangeDataHashUsage, + EnvVars: []string{"DSLIM_XRAY_CHANGE_DATA_HASH"}, + }, + FlagChangeMatchLayersOnly: &cli.BoolFlag{ + Name: FlagChangeMatchLayersOnly, + Usage: FlagChangeMatchLayersOnlyUsage, + EnvVars: []string{"DSLIM_XRAY_CHANGE_MATCH_LAYERS_ONLY"}, + }, + FlagExportAllDataArtifacts: &cli.StringFlag{ + Name: FlagExportAllDataArtifacts, + Usage: FlagExportAllDataArtifactsUsage, + EnvVars: []string{"DSLIM_XRAY_EXPORT_ALL_DARTIFACTS"}, + }, + FlagDetectAllCertFiles: &cli.BoolFlag{ + Name: FlagDetectAllCertFiles, + Usage: FlagDetectAllCertFilesUsage, + EnvVars: []string{"DSLIM_XRAY_DETECT_ALL_CERTS"}, + }, + FlagDetectAllCertPKFiles: &cli.BoolFlag{ + Name: FlagDetectAllCertPKFiles, + Usage: FlagDetectAllCertPKFilesUsage, + EnvVars: []string{"DSLIM_XRAY_DETECT_ALL_CERT_PKS"}, }, } diff --git a/vendor/github.com/urfave/cli/.gitignore b/vendor/github.com/urfave/cli/.gitignore deleted file mode 100644 index 9c2506032c..0000000000 --- a/vendor/github.com/urfave/cli/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -*.coverprofile -node_modules/ -vendor -.idea \ No newline at end of file diff --git a/vendor/github.com/urfave/cli/appveyor.yml b/vendor/github.com/urfave/cli/appveyor.yml deleted file mode 100644 index 8ef2fea1a6..0000000000 --- a/vendor/github.com/urfave/cli/appveyor.yml +++ /dev/null @@ -1,28 +0,0 @@ -version: "{build}" - -os: Windows Server 2016 - -image: Visual Studio 2017 - -clone_folder: c:\gopath\src\github.com\urfave\cli - -cache: - - node_modules - -environment: - GOPATH: C:\gopath - GOVERSION: 1.11.x - GO111MODULE: on - GOPROXY: https://proxy.golang.org - -install: - - set PATH=%GOPATH%\bin;C:\go\bin;%PATH% - - go version - - go env - - go get github.com/urfave/gfmrun/cmd/gfmrun - - go mod vendor - -build_script: - - go run build.go vet - - go run build.go test - - go run build.go gfmrun docs/v1/manual.md 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 957f39e0f4..0000000000 --- a/vendor/github.com/urfave/cli/context.go +++ /dev/null @@ -1,347 +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 { - // Check if a flag is set - if isSet { - // If the flag is set, also set its other aliases - eachName(f.GetName(), func(name string) { - c.setFlags[name] = true - }) - } - - 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/errors.go b/vendor/github.com/urfave/cli/errors.go deleted file mode 100644 index 562b2953cf..0000000000 --- a/vendor/github.com/urfave/cli/errors.go +++ /dev/null @@ -1,115 +0,0 @@ -package cli - -import ( - "fmt" - "io" - "os" - "strings" -) - -// OsExiter is the function used when the app exits. If not set defaults to os.Exit. -var OsExiter = os.Exit - -// ErrWriter is used to write errors to the user. This can be anything -// implementing the io.Writer interface and defaults to os.Stderr. -var ErrWriter io.Writer = os.Stderr - -// MultiError is an error that wraps multiple errors. -type MultiError struct { - Errors []error -} - -// NewMultiError creates a new MultiError. Pass in one or more errors. -func NewMultiError(err ...error) MultiError { - return MultiError{Errors: err} -} - -// Error implements the error interface. -func (m MultiError) Error() string { - errs := make([]string, len(m.Errors)) - for i, err := range m.Errors { - errs[i] = err.Error() - } - - return strings.Join(errs, "\n") -} - -type ErrorFormatter interface { - Format(s fmt.State, verb rune) -} - -// ExitCoder is the interface checked by `App` and `Command` for a custom exit -// code -type ExitCoder interface { - error - ExitCode() int -} - -// ExitError fulfills both the builtin `error` interface and `ExitCoder` -type ExitError struct { - exitCode int - message interface{} -} - -// NewExitError makes a new *ExitError -func NewExitError(message interface{}, exitCode int) *ExitError { - return &ExitError{ - exitCode: exitCode, - message: message, - } -} - -// Error returns the string message, fulfilling the interface required by -// `error` -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 { - return ee.exitCode -} - -// HandleExitCoder checks if the error fulfills the ExitCoder interface, and if -// so prints the error to stderr (if it is non-empty) and calls OsExiter with the -// given exit code. If the given error is a MultiError, then this func is -// called on all members of the Errors slice and calls OsExiter with the last exit code. -func HandleExitCoder(err error) { - if err == nil { - return - } - - if exitErr, ok := err.(ExitCoder); ok { - if err.Error() != "" { - if _, ok := exitErr.(ErrorFormatter); ok { - fmt.Fprintf(ErrWriter, "%+v\n", err) - } else { - fmt.Fprintln(ErrWriter, err) - } - } - OsExiter(exitErr.ExitCode()) - return - } - - if multiErr, ok := err.(MultiError); ok { - code := handleMultiError(multiErr) - OsExiter(code) - return - } -} - -func handleMultiError(multiErr MultiError) int { - code := 1 - for _, merr := range multiErr.Errors { - if multiErr2, ok := merr.(MultiError); ok { - code = handleMultiError(multiErr2) - } else { - fmt.Fprintln(ErrWriter, merr) - if exitErr, ok := merr.(ExitCoder); ok { - code = exitErr.ExitCode() - } - } - } - return code -} 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 2602408cf7..0000000000 --- a/vendor/github.com/urfave/cli/flag_int64_slice.go +++ /dev/null @@ -1,197 +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 { - slice := make([]string, len(*f)) - for i, v := range *f { - slice[i] = strconv.FormatInt(v, 10) - } - - return strings.Join(slice, ",") -} - -// 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 { - value, ok := f.Value.(*Int64Slice) - if !ok { - return nil - } - - // extract the slice from asserted value - parsed := value.Value() - - // extract default value from the flag - var defaultVal []int64 - for _, v := range strings.Split(f.DefValue, ",") { - if v != "" { - int64Value, err := strconv.ParseInt(v, 10, 64) - if err != nil { - panic(err) - } - defaultVal = append(defaultVal, int64Value) - } - } - // if the current value is not equal to the default value - // remove the default values from the flag - if !isInt64SliceEqual(parsed, defaultVal) { - for _, v := range defaultVal { - parsed = removeFromInt64Slice(parsed, v) - } - } - return parsed - } - return nil -} - -func removeFromInt64Slice(slice []int64, val int64) []int64 { - for i, v := range slice { - if v == val { - return append(slice[:i], slice[i+1:]...) - } - } - return slice -} - -func isInt64SliceEqual(newValue, defaultValue []int64) bool { - // If one is nil, the other must also be nil. - if (newValue == nil) != (defaultValue == nil) { - return false - } - - if len(newValue) != len(defaultValue) { - return false - } - - for i, v := range newValue { - if v != defaultValue[i] { - return false - } - } - - return true -} 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 a423d1ecb8..0000000000 --- a/vendor/github.com/urfave/cli/flag_int_slice.go +++ /dev/null @@ -1,196 +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 { - slice := make([]string, len(*f)) - for i, v := range *f { - slice[i] = strconv.Itoa(v) - } - - return strings.Join(slice, ",") -} - -// 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 { - value, ok := f.Value.(*IntSlice) - if !ok { - return nil - } - // extract the slice from asserted value - slice := value.Value() - - // extract default value from the flag - var defaultVal []int - for _, v := range strings.Split(f.DefValue, ",") { - if v != "" { - intValue, err := strconv.Atoi(v) - if err != nil { - panic(err) - } - defaultVal = append(defaultVal, intValue) - } - } - // if the current value is not equal to the default value - // remove the default values from the flag - if !isIntSliceEqual(slice, defaultVal) { - for _, v := range defaultVal { - slice = removeFromIntSlice(slice, v) - } - } - return slice - } - return nil -} - -func removeFromIntSlice(slice []int, val int) []int { - for i, v := range slice { - if v == val { - return append(slice[:i], slice[i+1:]...) - } - } - return slice -} - -func isIntSliceEqual(newValue, defaultValue []int) bool { - // If one is nil, the other must also be nil. - if (newValue == nil) != (defaultValue == nil) { - return false - } - - if len(newValue) != len(defaultValue) { - return false - } - - for i, v := range newValue { - if v != defaultValue[i] { - return false - } - } - - return true -} 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 c6cb442545..0000000000 --- a/vendor/github.com/urfave/cli/flag_string_slice.go +++ /dev/null @@ -1,182 +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 strings.Join(*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 { - value, ok := f.Value.(*StringSlice) - if !ok { - return nil - } - // extract the slice from asserted value - slice := value.Value() - - // extract default value from the flag - var defaultVal []string - for _, v := range strings.Split(f.DefValue, ",") { - defaultVal = append(defaultVal, v) - } - - // if the current value is not equal to the default value - // remove the default values from the flag - if !isStringSliceEqual(slice, defaultVal) { - for _, v := range defaultVal { - slice = removeFromStringSlice(slice, v) - } - } - return slice - } - return nil -} - -func removeFromStringSlice(slice []string, val string) []string { - for i, v := range slice { - if v == val { - return append(slice[:i], slice[i+1:]...) - } - } - return slice -} - -func isStringSliceEqual(newValue, defaultValue []string) bool { - // If one is nil, the other must also be nil. - if (newValue == nil) != (defaultValue == nil) { - return false - } - - if len(newValue) != len(defaultValue) { - return false - } - - for i, v := range newValue { - if v != defaultValue[i] { - return false - } - } - - return true -} 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/v2/.gitignore b/vendor/github.com/urfave/cli/v2/.gitignore new file mode 100644 index 0000000000..2d5e149b43 --- /dev/null +++ b/vendor/github.com/urfave/cli/v2/.gitignore @@ -0,0 +1,7 @@ +*.coverprofile +*.orig +node_modules/ +vendor +.idea +internal/*/built-example +coverage.txt 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 53% rename from vendor/github.com/urfave/cli/README.md rename to vendor/github.com/urfave/cli/v2/README.md index b2abbcf9db..408668bc3e 100644 --- a/vendor/github.com/urfave/cli/README.md +++ b/vendor/github.com/urfave/cli/v2/README.md @@ -1,9 +1,6 @@ cli === -[![Build Status](https://travis-ci.org/urfave/cli.svg?branch=master)](https://travis-ci.org/urfave/cli) -[![Windows Build Status](https://ci.appveyor.com/api/projects/status/rtgk5xufi932pb2v?svg=true)](https://ci.appveyor.com/project/urfave/cli) - [![GoDoc](https://godoc.org/github.com/urfave/cli?status.svg)](https://godoc.org/github.com/urfave/cli) [![codebeat](https://codebeat.co/badges/0a8f30aa-f975-404b-b878-5fab3ae1cc5f)](https://codebeat.co/projects/github-com-urfave-cli) [![Go Report Card](https://goreportcard.com/badge/urfave/cli)](https://goreportcard.com/report/urfave/cli) @@ -15,56 +12,59 @@ 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). +Guides for migrating to newer versions: -### GOPATH +- `v1-to-v2` - [./docs/migrate-v1-to-v2.md](./docs/migrate-v1-to-v2.md) -Make sure your `PATH` includes the `$GOPATH/bin` directory so your commands can -be easily used: -``` -export PATH=$PATH:$GOPATH/bin -``` +## Installation -### Supported platforms +Using this package requires a working Go environment. [See the install instructions for Go](http://golang.org/doc/install.html). -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 Modules are required when using this package. [See the go blog guide on using Go Modules](https://blog.golang.org/using-go-modules). -### Using `v1` releases +### Using `v2` releases ``` -$ go get github.com/urfave/cli +$ GO111MODULE=on go get github.com/urfave/cli/v2 ``` ```go ... import ( - "github.com/urfave/cli" + "github.com/urfave/cli/v2" // imports as package "cli" ) ... ``` -### Using `v2` releases - -**Warning**: `v2` is in a pre-release state. +### Using `v1` releases ``` -$ go get github.com/urfave/cli.v2 +$ GO111MODULE=on go get github.com/urfave/cli ``` ```go ... import ( - "github.com/urfave/cli.v2" // imports as package "cli" + "github.com/urfave/cli" ) ... ``` + +### GOPATH + +Make sure your `PATH` includes the `$GOPATH/bin` directory so your commands can +be easily used: +``` +export PATH=$PATH:$GOPATH/bin +``` + +### 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. This project uses Github Actions for +builds. To see our currently supported go versions and platforms, look at the [./.github/workflows/cli.yml](https://github.com/urfave/cli/blob/master/.github/workflows/cli.yml). diff --git a/vendor/github.com/urfave/cli/app.go b/vendor/github.com/urfave/cli/v2/app.go similarity index 77% rename from vendor/github.com/urfave/cli/app.go rename to vendor/github.com/urfave/cli/v2/app.go index ddb7685d62..f801fce910 100644 --- a/vendor/github.com/urfave/cli/app.go +++ b/vendor/github.com/urfave/cli/v2/app.go @@ -1,6 +1,7 @@ package cli import ( + "context" "flag" "fmt" "io" @@ -11,14 +12,10 @@ import ( ) var ( - changeLogURL = "https://github.com/urfave/cli/blob/master/CHANGELOG.md" + changeLogURL = "https://github.com/urfave/cli/blob/master/docs/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,18 +38,21 @@ 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 EnableBashCompletion bool - // Boolean to hide built-in help command + // Boolean to hide built-in help command and help flag HideHelp bool + // Boolean to hide built-in help command but keep help flag. + // Ignored if HideHelp is true. + HideHelpCommand 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,32 +60,27 @@ 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 + // Execute this function if a usage error occurs OnUsageError OnUsageErrorFunc // 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 + // Reader reader to write input to (useful for tests) + Reader io.Reader // Writer writer to write output to Writer io.Writer // ErrWriter writes error output ErrWriter io.Writer - // Execute this function to handle ExitErrors. If not provided, HandleExitCoder is provided to - // function as a default, so this is optional. + // ExitErrHandler processes any error encountered while running an App before + // it is returned to the caller. If no function is provided, HandleExitCoder + // is used as the default behavior. ExitErrHandler ExitErrHandlerFunc // Other custom info Metadata map[string]interface{} @@ -96,7 +91,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 @@ -124,7 +119,9 @@ func NewApp() *App { BashComplete: DefaultAppComplete, Action: helpCommand.Action, Compiled: compileTime(), + Reader: os.Stdin, Writer: os.Stdout, + ErrWriter: os.Stderr, } } @@ -138,47 +135,79 @@ 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.HideVersion = true + } + + if a.BashComplete == nil { + a.BashComplete = DefaultAppComplete + } + + if a.Action == nil { + a.Action = helpCommand.Action + } + + if a.Compiled == (time.Time{}) { + a.Compiled = compileTime() + } + + if a.Reader == nil { + a.Reader = os.Stdin } - var newCmds []Command + if a.Writer == nil { + a.Writer = os.Stdout + } + + if a.ErrWriter == nil { + a.ErrWriter = os.Stderr + } + + 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.appendFlag(HelpFlag) + if !a.HideHelpCommand { + a.appendCommand(helpCommand) } - } - if a.Version == "" { - a.HideVersion = true + if HelpFlag != nil { + a.appendFlag(HelpFlag) + } } if !a.HideVersion { 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{}) } - - if a.Writer == nil { - a.Writer = os.Stdout - } } func (a *App) newFlagSet() (*flag.FlagSet, error) { @@ -192,6 +221,13 @@ func (a *App) useShortOptionHandling() bool { // Run is the entry point to the cli app. Parses the arguments slice and routes // to the proper flag/args combination func (a *App) Run(arguments []string) (err error) { + return a.RunContext(context.Background(), arguments) +} + +// RunContext is like Run except it takes a Context that will be +// passed to its commands and sub-commands. Through this, you can +// propagate timeouts and cancellation requests +func (a *App) RunContext(ctx context.Context, arguments []string) (err error) { a.Setup() // handle the completion flag separately from the flagset since @@ -209,7 +245,7 @@ func (a *App) Run(arguments []string) (err error) { err = parseIter(set, a, arguments[1:], shellComplete) nerr := normalizeFlags(a.Flags, set) - context := NewContext(a, set, nil) + context := NewContext(a, set, &Context{Context: ctx}) if nerr != nil { _, _ = fmt.Fprintln(a.Writer, nerr) _ = ShowAppHelp(context) @@ -252,7 +288,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 } @@ -263,8 +299,6 @@ func (a *App) Run(arguments []string) (err error) { if a.Before != nil { beforeErr := a.Before(context) if beforeErr != nil { - _, _ = fmt.Fprintf(a.Writer, "%v\n\n", beforeErr) - _ = ShowAppHelp(context) a.handleExitCoder(context, beforeErr) err = beforeErr return err @@ -285,7 +319,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 @@ -298,7 +332,7 @@ func (a *App) Run(arguments []string) (err error) { // code in the cli.ExitCoder func (a *App) RunAndExitOnError() { if err := a.Run(os.Args); err != nil { - _, _ = fmt.Fprintln(a.errWriter(), err) + _, _ = fmt.Fprintln(a.ErrWriter, err) OsExiter(1) } } @@ -306,17 +340,10 @@ 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) { - // 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.appendFlag(HelpFlag) - } - } - } + // Setup also handles HideHelp and HideHelpCommand + a.Setup() - newCmds := []Command{} + var newCmds []*Command for _, c := range a.Commands { if c.HelpName == "" { c.HelpName = fmt.Sprintf("%s %s", a.HelpName, c.Name) @@ -382,7 +409,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 } @@ -409,7 +436,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 @@ -419,28 +446,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 { @@ -451,8 +471,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) @@ -466,28 +486,15 @@ func (a *App) VisibleFlags() []Flag { return visibleFlags(a.Flags) } -func (a *App) hasFlag(flag Flag) bool { - for _, f := range a.Flags { - if flag == f { - return true - } +func (a *App) appendFlag(fl Flag) { + if !hasFlag(a.Flags, fl) { + a.Flags = append(a.Flags, fl) } - - return false -} - -func (a *App) errWriter() io.Writer { - // When the app ErrWriter is nil use the package level one. - if a.ErrWriter == nil { - return ErrWriter - } - - return a.ErrWriter } -func (a *App) appendFlag(flag Flag) { - if !a.hasFlag(flag) { - a.Flags = append(a.Flags, flag) +func (a *App) appendCommand(c *Command) { + if !hasCommand(a.Commands, c) { + a.Commands = append(a.Commands, c) } } @@ -506,7 +513,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/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..867e3908ca --- /dev/null +++ b/vendor/github.com/urfave/cli/v2/category.go @@ -0,0 +1,79 @@ +package cli + +// CommandCategories interface allows for category manipulation +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 56% rename from vendor/github.com/urfave/cli/command.go rename to vendor/github.com/urfave/cli/v2/command.go index 24e9e5c572..dda2f49a0a 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,25 +32,20 @@ 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 + // Boolean to hide built-in help command and help flag HideHelp bool + // Boolean to hide built-in help command but keep help flag + // Ignored if HideHelp is true. + HideHelpCommand bool // Boolean to hide this command from help or completion Hidden bool // Boolean to enable short-option handling so user can combine several @@ -70,7 +63,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 +81,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(), ctx.shellComplete) + set, err := c.parseFlags(ctx.Args(), ctx.shellComplete) context := NewContext(ctx.App, set, ctx) context.Command = c @@ -124,7 +113,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 +139,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 } @@ -161,7 +150,6 @@ func (c Command) Run(ctx *Context) (err error) { if c.Before != nil { err = c.Before(context) if err != nil { - _ = ShowCommandHelp(context, c.Name) context.App.handleExitCoder(context, err) return err } @@ -171,7 +159,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 +168,25 @@ func (c Command) Run(ctx *Context) (err error) { return err } -func (c *Command) parseFlags(args Args, shellComplete bool) (*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, shellComplete bool) (*flag.FlagSet, error) { set, err := c.newFlagSet() if err != nil { return nil, err } - err = parseIter(set, c, args, shellComplete) + if c.SkipFlagParsing { + return set, set.Parse(append([]string{"--"}, args.Tail()...)) + } + + err = parseIter(set, c, args.Tail(), shellComplete) if err != nil { return nil, err } @@ -211,96 +199,13 @@ func (c *Command) parseFlags(args Args, shellComplete bool) (*flag.FlagSet, erro 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 +214,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 { @@ -333,22 +238,22 @@ func (c Command) startApp(ctx *Context) error { app.Commands = c.Subcommands app.Flags = c.Flags app.HideHelp = c.HideHelp + app.HideHelpCommand = c.HideHelpCommand app.Version = ctx.App.Version - app.HideVersion = ctx.App.HideVersion + app.HideVersion = true 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 +279,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..74ed51912e --- /dev/null +++ b/vendor/github.com/urfave/cli/v2/context.go @@ -0,0 +1,273 @@ +package cli + +import ( + "context" + "errors" + "flag" + "fmt" + "strings" +) + +// 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 + 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 + if parentCtx.flagSet == nil { + parentCtx.flagSet = &flag.FlagSet{} + } + } + + c.Command = &Command{} + + if c.Context == nil { + c.Context = context.Background() + } + + 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 91% rename from vendor/github.com/urfave/cli/docs.go rename to vendor/github.com/urfave/cli/v2/docs.go index 5b94566128..dc16fc82d4 100644 --- a/vendor/github.com/urfave/cli/docs.go +++ b/vendor/github.com/urfave/cli/v2/docs.go @@ -48,15 +48,14 @@ func (a *App) writeDocTemplate(w io.Writer) error { return t.ExecuteTemplate(w, name, &cliTemplate{ App: a, Commands: prepareCommands(a.Commands, 0), - GlobalArgs: prepareArgsWithValues(a.Flags), - SynopsisArgs: prepareArgsSynopsis(a.Flags), + GlobalArgs: prepareArgsWithValues(a.VisibleFlags()), + SynopsisArgs: prepareArgsSynopsis(a.VisibleFlags()), }) } -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/v2/errors.go b/vendor/github.com/urfave/cli/v2/errors.go new file mode 100644 index 0000000000..751ef9b166 --- /dev/null +++ b/vendor/github.com/urfave/cli/v2/errors.go @@ -0,0 +1,141 @@ +package cli + +import ( + "fmt" + "io" + "os" + "strings" +) + +// OsExiter is the function used when the app exits. If not set defaults to os.Exit. +var OsExiter = os.Exit + +// ErrWriter is used to write errors to the user. This can be anything +// implementing the io.Writer interface and defaults to os.Stderr. +var ErrWriter io.Writer = os.Stderr + +// MultiError is an error that wraps multiple errors. +type MultiError interface { + error + Errors() []error +} + +// newMultiError creates a new MultiError. Pass in one or more errors. +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)) + 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 +} + +// ErrorFormatter is the interface that will suitably format the error output +type ErrorFormatter interface { + Format(s fmt.State, verb rune) +} + +// ExitCoder is the interface checked by `App` and `Command` for a custom exit +// code +type ExitCoder interface { + error + ExitCode() int +} + +type exitError struct { + exitCode int + message interface{} +} + +// NewExitError calls Exit to create a new ExitCoder. +// +// Deprecated: This function is a duplicate of Exit and will eventually be removed. +func NewExitError(message interface{}, exitCode int) ExitCoder { + return Exit(message, exitCode) +} + +// Exit wraps a message and exit code into an error, which by default is +// handled with a call to os.Exit during default error handling. +// +// This is the simplest way to trigger a non-zero exit code for an App without +// having to call os.Exit manually. During testing, this behavior can be avoided +// by overiding the ExitErrHandler function on an App or the package-global +// OsExiter function. +func Exit(message interface{}, exitCode int) ExitCoder { + return &exitError{ + message: message, + exitCode: exitCode, + } +} + +func (ee *exitError) Error() string { + return fmt.Sprintf("%v", ee.message) +} + +func (ee *exitError) ExitCode() int { + return ee.exitCode +} + +// HandleExitCoder handles errors implementing ExitCoder by printing their +// message and calling OsExiter with the given exit code. +// +// If the given error instead implements MultiError, each error will be checked +// for the ExitCoder interface, and OsExiter will be called with the last exit +// code found, or exit code 1 if no ExitCoder is found. +// +// This function is the default error-handling behavior for an App. +func HandleExitCoder(err error) { + if err == nil { + return + } + + if exitErr, ok := err.(ExitCoder); ok { + if err.Error() != "" { + if _, ok := exitErr.(ErrorFormatter); ok { + _, _ = fmt.Fprintf(ErrWriter, "%+v\n", err) + } else { + _, _ = fmt.Fprintln(ErrWriter, err) + } + } + OsExiter(exitErr.ExitCode()) + return + } + + if multiErr, ok := err.(MultiError); ok { + code := handleMultiError(multiErr) + OsExiter(code) + return + } +} + +func handleMultiError(multiErr MultiError) int { + code := 1 + for _, merr := range multiErr.Errors() { + if multiErr2, ok := merr.(MultiError); ok { + code = handleMultiError(multiErr2) + } else if merr != nil { + fmt.Fprintln(ErrWriter, merr) + if exitErr, ok := merr.(ExitCoder); ok { + code = exitErr.ExitCode() + } + } + } + return code +} diff --git a/vendor/github.com/urfave/cli/fish.go b/vendor/github.com/urfave/cli/v2/fish.go similarity index 92% rename from vendor/github.com/urfave/cli/fish.go rename to vendor/github.com/urfave/cli/v2/fish.go index cf183af611..588e070eab 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,19 @@ 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: if f.TakesFile { return } - case StringFlag: + case *StringSliceFlag: if f.TakesFile { return } - case StringSliceFlag: + case *PathFlag: 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 53% rename from vendor/github.com/urfave/cli/flag.go rename to vendor/github.com/urfave/cli/v2/flag.go index 1cfa1cdb21..ad97c2d058 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 or HideHelpCommand 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,37 @@ 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(name string, aliases []string) []string { + var ret []string + + 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 withFileHint(filePath, str string) string { fileText := "" if filePath != "" { @@ -217,51 +244,49 @@ func flagValue(f Flag) reflect.Value { return fv } +func formatDefault(format string) string { + return " (default: " + format + ")" +} + 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)), - ), - ) + switch f := f.(type) { + case *IntSliceFlag: + return withEnvHint(flagStringSliceField(f, "EnvVars"), + stringifyIntSliceFlag(f)) + case *Int64SliceFlag: + return withEnvHint(flagStringSliceField(f, "EnvVars"), + stringifyInt64SliceFlag(f)) + case *Float64SliceFlag: + return withEnvHint(flagStringSliceField(f, "EnvVars"), + stringifyFloat64SliceFlag(f)) + case *StringSliceFlag: + return withEnvHint(flagStringSliceField(f, "EnvVars"), + stringifyStringSliceFlag(f)) } placeholder, usage := unquoteUsage(fv.FieldByName("Usage").String()) needsPlaceholder := false defaultValueString := "" - - if val := fv.FieldByName("Value"); val.IsValid() { - needsPlaceholder = true - defaultValueString = fmt.Sprintf(" (default: %v)", val.Interface()) + val := fv.FieldByName("Value") + if val.IsValid() { + needsPlaceholder = val.Kind() != reflect.Bool + defaultValueString = fmt.Sprintf(formatDefault("%v"), val.Interface()) if val.Kind() == reflect.String && val.String() != "" { - defaultValueString = fmt.Sprintf(" (default: %q)", val.String()) + defaultValueString = fmt.Sprintf(formatDefault("%q"), val.String()) } } - if defaultValueString == " (default: )" { + helpText := fv.FieldByName("DefaultText") + if helpText.IsValid() && helpText.String() != "" { + needsPlaceholder = val.Kind() != reflect.Bool + defaultValueString = fmt.Sprintf(formatDefault("%s"), helpText.String()) + } + + if defaultValueString == formatDefault("") { defaultValueString = "" } @@ -271,16 +296,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 +308,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 +319,22 @@ func stringifyInt64SliceFlag(f Int64SliceFlag) string { } } - return stringifySliceFlag(f.Usage, f.Name, defaultVals) + return stringifySliceFlag(f.Usage, f.Names(), defaultVals) } -func stringifyStringSliceFlag(f StringSliceFlag) string { +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 { var defaultVals []string if f.Value != nil && len(f.Value.Value()) > 0 { for _, s := range f.Value.Value() { @@ -312,10 +344,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 @@ -323,18 +355,28 @@ func stringifySliceFlag(usage, name string, defaultVals []string) string { defaultVal := "" if len(defaultVals) > 0 { - defaultVal = fmt.Sprintf(" (default: %s)", strings.Join(defaultVals, ", ")) + defaultVal = fmt.Sprintf(formatDefault("%s"), strings.Join(defaultVals, ", ")) + } + + 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 + } } - usageWithDefault := strings.TrimSpace(usage + defaultVal) - return FlagNamePrefixer(name, placeholder) + "\t" + usageWithDefault + 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..bc9ea35d08 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.Name, f.Aliases) } // 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..22a2e67201 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.Name, f.Aliases) } // 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..91c778c873 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.Name, f.Aliases) } // 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..706ee6cd4b --- /dev/null +++ b/vendor/github.com/urfave/cli/v2/flag_float64_slice.go @@ -0,0 +1,163 @@ +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.Name, f.Aliases) +} + +// 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 { + if slice, ok := f.Value.(*Float64Slice); ok { + return slice.Value() + } + } + 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..b0c8ff44d2 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.Name, f.Aliases) } // 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..ac39d4a9e4 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.Name, f.Aliases) } // 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..e09991269b 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.Name, f.Aliases) } // 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..6c7fd9376d --- /dev/null +++ b/vendor/github.com/urfave/cli/v2/flag_int64_slice.go @@ -0,0 +1,159 @@ +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.Name, f.Aliases) +} + +// 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 { + if slice, ok := f.Value.(*Int64Slice); ok { + return slice.Value() + } + } + 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..4e0afc0210 --- /dev/null +++ b/vendor/github.com/urfave/cli/v2/flag_int_slice.go @@ -0,0 +1,173 @@ +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.Name, f.Aliases) +} + +// 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 { + if slice, ok := f.Value.(*IntSlice); ok { + return slice.Value() + } + } + 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..8070dc4b0b --- /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.Name, f.Aliases) +} + +// 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 +} + +// Path 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..400bb532e7 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.Name, f.Aliases) } // 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..35497032cb --- /dev/null +++ b/vendor/github.com/urfave/cli/v2/flag_string_slice.go @@ -0,0 +1,180 @@ +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 + Destination *StringSlice +} + +// 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.Name, f.Aliases) +} + +// 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 f.Destination != nil && f.Value != nil { + f.Destination.slice = make([]string, len(f.Value.slice)) + copy(f.Destination.slice, f.Value.slice) + + } + + if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { + if f.Value == nil { + f.Value = &StringSlice{} + } + destination := f.Value + if f.Destination != nil { + destination = f.Destination + } + + for _, s := range strings.Split(val, ",") { + if err := destination.Set(strings.TrimSpace(s)); err != nil { + return fmt.Errorf("could not parse %q as string value for flag %s: %s", val, f.Name, err) + } + } + + // Set this to false so that we reset the slice if we then set values from + // flags that have already been set by the environment. + destination.hasBeenSet = false + f.HasBeenSet = true + } + + for _, name := range f.Names() { + if f.Value == nil { + f.Value = &StringSlice{} + } + + if f.Destination != nil { + set.Var(f.Destination, name, f.Usage) + continue + } + + 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 { + if slice, ok := f.Value.(*StringSlice); ok { + return slice.Value() + } + } + return nil +} diff --git a/vendor/github.com/urfave/cli/v2/flag_timestamp.go b/vendor/github.com/urfave/cli/v2/flag_timestamp.go new file mode 100644 index 0000000000..0382a6b9dc --- /dev/null +++ b/vendor/github.com/urfave/cli/v2/flag_timestamp.go @@ -0,0 +1,154 @@ +package cli + +import ( + "flag" + "fmt" + "time" +) + +// Timestamp wrap to satisfy golang's flag interface. +type Timestamp struct { + timestamp *time.Time + hasBeenSet bool + layout string +} + +// Timestamp constructor +func NewTimestamp(timestamp time.Time) *Timestamp { + return &Timestamp{timestamp: ×tamp} +} + +// Set the timestamp value directly +func (t *Timestamp) SetTimestamp(value time.Time) { + if !t.hasBeenSet { + t.timestamp = &value + t.hasBeenSet = true + } +} + +// Set the timestamp string layout for future parsing +func (t *Timestamp) SetLayout(layout string) { + t.layout = layout +} + +// Parses the string value to timestamp +func (t *Timestamp) Set(value string) error { + timestamp, err := time.Parse(t.layout, value) + if err != nil { + return err + } + + t.timestamp = ×tamp + t.hasBeenSet = true + return nil +} + +// String returns a readable representation of this value (for usage defaults) +func (t *Timestamp) String() string { + return fmt.Sprintf("%#v", t.timestamp) +} + +// Value returns the timestamp value stored in the flag +func (t *Timestamp) Value() *time.Time { + return t.timestamp +} + +// Get returns the flag structure +func (t *Timestamp) Get() interface{} { + return *t +} + +// TimestampFlag is a flag with type time +type TimestampFlag struct { + Name string + Aliases []string + Usage string + EnvVars []string + FilePath string + Required bool + Hidden bool + Layout string + Value *Timestamp + DefaultText string + HasBeenSet bool +} + +// IsSet returns whether or not the flag has been set through env or file +func (f *TimestampFlag) IsSet() bool { + return f.HasBeenSet +} + +// String returns a readable representation of this value +// (for usage defaults) +func (f *TimestampFlag) String() string { + return FlagStringer(f) +} + +// Names returns the names of the flag +func (f *TimestampFlag) Names() []string { + return flagNames(f.Name, f.Aliases) +} + +// IsRequired returns whether or not the flag is required +func (f *TimestampFlag) IsRequired() bool { + return f.Required +} + +// TakesValue returns true of the flag takes a value, otherwise false +func (f *TimestampFlag) TakesValue() bool { + return true +} + +// GetUsage returns the usage string for the flag +func (f *TimestampFlag) 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 *TimestampFlag) GetValue() string { + if f.Value != nil { + return f.Value.timestamp.String() + } + return "" +} + +// Apply populates the flag given the flag set and environment +func (f *TimestampFlag) Apply(set *flag.FlagSet) error { + if f.Layout == "" { + return fmt.Errorf("timestamp Layout is required") + } + if f.Value == nil { + f.Value = &Timestamp{} + } + f.Value.SetLayout(f.Layout) + + if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok { + if err := f.Value.Set(val); err != nil { + return fmt.Errorf("could not parse %q as timestamp value for flag %s: %s", val, f.Name, err) + } + f.HasBeenSet = true + } + + for _, name := range f.Names() { + set.Var(f.Value, name, f.Usage) + } + return nil +} + +// Timestamp gets the timestamp from a flag name +func (c *Context) Timestamp(name string) *time.Time { + if fs := lookupFlagSet(name, c); fs != nil { + return lookupTimestamp(name, fs) + } + return nil +} + +// Fetches the timestamp value from the local timestampWrap +func lookupTimestamp(name string, set *flag.FlagSet) *time.Time { + f := set.Lookup(name) + if f != nil { + return (f.Value.(*Timestamp)).Value() + } + 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..2e5e76b0ea 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.Name, f.Aliases) } // 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..8fc3289d82 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.Name, f.Aliases) } // 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 68% rename from vendor/github.com/urfave/cli/go.mod rename to vendor/github.com/urfave/cli/v2/go.mod index 7d04d20167..1139664326 100644 --- a/vendor/github.com/urfave/cli/go.mod +++ b/vendor/github.com/urfave/cli/v2/go.mod @@ -1,9 +1,9 @@ -module github.com/urfave/cli +module github.com/urfave/cli/v2 go 1.11 require ( github.com/BurntSushi/toml v0.3.1 github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d - gopkg.in/yaml.v2 v2.2.2 + gopkg.in/yaml.v2 v2.2.3 ) diff --git a/vendor/github.com/urfave/cli/go.sum b/vendor/github.com/urfave/cli/v2/go.sum similarity index 89% rename from vendor/github.com/urfave/cli/go.sum rename to vendor/github.com/urfave/cli/v2/go.sum index ef121ff5db..663ad72768 100644 --- a/vendor/github.com/urfave/cli/go.sum +++ b/vendor/github.com/urfave/cli/v2/go.sum @@ -10,5 +10,5 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5I github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.3 h1:fvjTMHxHEw/mxHbtzPi3JCcKXQRAnQTBRo6YCJSVHKI= +gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/vendor/github.com/urfave/cli/help.go b/vendor/github.com/urfave/cli/v2/help.go similarity index 85% rename from vendor/github.com/urfave/cli/help.go rename to vendor/github.com/urfave/cli/v2/help.go index 2280e338ef..0a421ee99a 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", @@ -72,13 +72,13 @@ func ShowAppHelpAndExit(c *Context, exitCode int) { // ShowAppHelp is an action that displays the help. func ShowAppHelp(c *Context) error { - template := c.App.CustomAppHelpTemplate - if template == "" { - template = AppHelpTemplate + tpl := c.App.CustomAppHelpTemplate + if tpl == "" { + tpl = AppHelpTemplate } if c.App.ExtraInfo == nil { - HelpPrinter(c.App.Writer, template, c.App) + HelpPrinter(c.App.Writer, tpl, c.App) return nil } @@ -87,7 +87,7 @@ func ShowAppHelp(c *Context) error { "ExtraInfo": c.App.ExtraInfo, } } - HelpPrinterCustom(c.App.Writer, template, c.App, customAppData()) + HelpPrinterCustom(c.App.Writer, tpl, c.App, customAppData()) return nil } @@ -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,16 +207,30 @@ 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) return nil } +// ShowSubcommandHelpAndExit - Prints help for the given subcommand and exits with exit code. +func ShowSubcommandHelpAndExit(c *Context, exitCode int) { + _ = ShowSubcommandHelp(c) + os.Exit(exitCode) +} + // 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 @@ -255,7 +269,10 @@ func ShowCommandCompletions(ctx *Context, command string) { // allow using arbitrary functions in template rendering. func printHelpCustom(out io.Writer, templ string, data interface{}, customFuncs map[string]interface{}) { funcMap := template.FuncMap{ - "join": strings.Join, + "join": strings.Join, + "indent": indent, + "nindent": nindent, + "trim": strings.TrimSpace, } for key, value := range customFuncs { funcMap[key] = value @@ -263,6 +280,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 +299,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 +343,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 } @@ -361,3 +375,12 @@ func checkCommandCompletions(c *Context, name string) bool { ShowCommandCompletions(c, name) return true } + +func indent(spaces int, v string) string { + pad := strings.Repeat(" ", spaces) + return pad + strings.Replace(v, "\n", "\n"+pad, -1) +} + +func nindent(spaces int, v string) string { + return "\n" + indent(spaces, v) +} 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 91% rename from vendor/github.com/urfave/cli/template.go rename to vendor/github.com/urfave/cli/v2/template.go index c631fb97dd..31c03f81c7 100644 --- a/vendor/github.com/urfave/cli/template.go +++ b/vendor/github.com/urfave/cli/v2/template.go @@ -13,14 +13,13 @@ VERSION: {{.Version}}{{end}}{{end}}{{if .Description}} DESCRIPTION: - {{.Description}}{{end}}{{if len .Authors}} + {{.Description | nindent 3 | trim}}{{end}}{{if len .Authors}} AUTHOR{{with $length := len .Authors}}{{if ne 1 $length}}S{{end}}{{end}}: {{range $index, $author := .Authors}}{{if $index}} {{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}} @@ -46,7 +45,7 @@ CATEGORY: {{.Category}}{{end}}{{if .Description}} DESCRIPTION: - {{.Description}}{{end}}{{if .VisibleFlags}} + {{.Description | nindent 3 | trim}}{{end}}{{if .VisibleFlags}} OPTIONS: {{range .VisibleFlags}}{{.}} @@ -57,13 +56,15 @@ OPTIONS: // cli.go uses text/template to render templates. You can // render custom help text by setting this variable. var SubcommandHelpTemplate = `NAME: - {{.HelpName}} - {{if .Description}}{{.Description}}{{else}}{{.Usage}}{{end}} + {{.HelpName}} - {{.Usage}} USAGE: - {{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} command{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}} + {{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} command{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Description}} -COMMANDS:{{range .VisibleCategories}}{{if .Name}} +DESCRIPTION: + {{.Description | nindent 3 | trim}}{{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}} @@ -73,9 +74,7 @@ OPTIONS: {{end}}{{end}} ` -var MarkdownDocTemplate = `% {{ .App.Name }}(8) {{ .App.Description }} - -% {{ .App.Author }} +var MarkdownDocTemplate = `% {{ .App.Name }} 8 # NAME diff --git a/vendor/modules.txt b/vendor/modules.txt index a81f78fa1a..8b0cc2da0e 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -203,8 +203,8 @@ github.com/ulikunitz/xz/internal/xlog github.com/ulikunitz/xz/lzma # github.com/ulyssessouza/godotenv v1.3.1-0.20210806120901-e417b721114e github.com/ulyssessouza/godotenv -# github.com/urfave/cli v1.22.4 -github.com/urfave/cli +# github.com/urfave/cli/v2 v2.3.0 +github.com/urfave/cli/v2 # go.opencensus.io v0.23.0 go.opencensus.io go.opencensus.io/internal