diff --git a/app.go b/app.go index e46e70f976..78e4314cbb 100644 --- a/app.go +++ b/app.go @@ -12,7 +12,7 @@ import ( "github.com/gopasspw/gopass/pkg/termio" "github.com/blang/semver" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func setupApp(ctx context.Context, sv semver.Version) *cli.App { @@ -65,11 +65,11 @@ func setupApp(ctx context.Context, sv semver.Version) *cli.App { } app.Flags = []cli.Flag{ - cli.BoolFlag{ + &cli.BoolFlag{ Name: "yes", Usage: "Assume yes on all yes/no questions or use the default on all others", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "clip, c", Usage: "Copy the first line of the secret into the clipboard", }, diff --git a/commands.go b/commands.go index 1a143fb54b..4e3fa9f52f 100644 --- a/commands.go +++ b/commands.go @@ -12,11 +12,11 @@ import ( "github.com/gopasspw/gopass/pkg/agent/client" "github.com/gopasspw/gopass/pkg/config" "github.com/gopasspw/gopass/pkg/ctxutil" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) -func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Command { - return []cli.Command{ +func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []*cli.Command { + return []*cli.Command{ { Name: "agent", Usage: "Start gopass-agent", @@ -35,7 +35,7 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com return e } }, - Subcommands: []cli.Command{ + Subcommands: []*cli.Command{ { Name: "client", Usage: "Start a simple agent test client", @@ -62,13 +62,14 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com return action.Audit(withGlobalFlags(ctx, c), c) }, Flags: []cli.Flag{ - cli.IntFlag{ - Name: "jobs, j", - Usage: "The number of jobs to run concurrently when auditing", - Value: 1, + &cli.IntFlag{ + Name: "jobs", + Aliases: []string{"j"}, + Usage: "The number of jobs to run concurrently when auditing", + Value: 1, }, }, - Subcommands: []cli.Command{ + Subcommands: []*cli.Command{ { Name: "hibp", Usage: "Detect leaked passwords", @@ -84,15 +85,17 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com return action.HIBP(withGlobalFlags(ctx, c), c) }, Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "force, f", - Usage: "Force to move the secret and overwrite existing one", + &cli.BoolFlag{ + Name: "force", + Aliases: []string{"f"}, + Usage: "Force to move the secret and overwrite existing one", }, - cli.BoolFlag{ - Name: "api, a", - Usage: "Use HIBP API", + &cli.BoolFlag{ + Name: "api", + Aliases: []string{"a"}, + Usage: "Use HIBP API", }, - cli.StringSliceFlag{ + &cli.StringSliceFlag{ Name: "dumps", Usage: "One or more HIBP v1/v2 dumps", }, @@ -106,7 +109,7 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com Description: "" + "These commands directly convert binary files from/to base64 encoding.", Aliases: []string{"bin"}, - Subcommands: []cli.Command{ + Subcommands: []*cli.Command{ { Name: "cat", Usage: "Print content of a secret to stdout, or insert from stdin", @@ -151,9 +154,10 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com }, BashComplete: func(c *cli.Context) { action.Complete(ctx, c) }, Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "force, f", - Usage: "Force to move the secret and overwrite existing one", + &cli.BoolFlag{ + Name: "force", + Aliases: []string{"f"}, + Usage: "Force to move the secret and overwrite existing one", }, }, }, @@ -175,9 +179,10 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com }, BashComplete: func(c *cli.Context) { action.Complete(ctx, c) }, Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "force, f", - Usage: "Force to move the secret and overwrite existing one", + &cli.BoolFlag{ + Name: "force", + Aliases: []string{"f"}, + Usage: "Force to move the secret and overwrite existing one", }, }, }, @@ -198,15 +203,15 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com return action.Clone(withGlobalFlags(ctx, c), c) }, Flags: []cli.Flag{ - cli.StringFlag{ + &cli.StringFlag{ Name: "path", Usage: "Path to clone the repo to", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "crypto", Usage: "Select crypto backend (gpg, gpgcli, plain, xc)", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "sync", Usage: "Select sync backend (git, gitcli, gogit, noop)", }, @@ -217,7 +222,7 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com Usage: "Bash and ZSH completion", Description: "" + "Source the output of this command with bash or zsh to get auto completion", - Subcommands: []cli.Command{{ + Subcommands: []*cli.Command{{ Name: "bash", Usage: "Source for auto completion in bash", Action: action.CompletionBash, @@ -254,7 +259,7 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com }, BashComplete: action.ConfigComplete, Flags: []cli.Flag{ - cli.StringFlag{ + &cli.StringFlag{ Name: "store", Usage: "Set value to substore config", }, @@ -276,9 +281,10 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com }, BashComplete: func(c *cli.Context) { action.Complete(ctx, c) }, Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "force, f", - Usage: "Force to copy the secret and overwrite existing one", + &cli.BoolFlag{ + Name: "force", + Aliases: []string{"f"}, + Usage: "Force to copy the secret and overwrite existing one", }, }, }, @@ -293,9 +299,10 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com return create.Create(withGlobalFlags(ctx, c), c, action.Store) }, Flags: []cli.Flag{ - cli.StringFlag{ - Name: "store, s", - Usage: "Which store to use", + &cli.StringFlag{ + Name: "store", + Aliases: []string{"s"}, + Usage: "Which store to use", }, }, }, @@ -312,13 +319,15 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com }, BashComplete: func(c *cli.Context) { action.Complete(ctx, c) }, Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "recursive, r", - Usage: "Recursive delete files and folders", + &cli.BoolFlag{ + Name: "recursive", + Aliases: []string{"r"}, + Usage: "Recursive delete files and folders", }, - cli.BoolFlag{ - Name: "force, f", - Usage: "Force to delete the secret", + &cli.BoolFlag{ + Name: "force", + Aliases: []string{"f"}, + Usage: "Force to delete the secret", }, }, }, @@ -338,13 +347,15 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com Aliases: []string{"set"}, BashComplete: func(c *cli.Context) { action.Complete(ctx, c) }, Flags: []cli.Flag{ - cli.StringFlag{ - Name: "editor, e", - Usage: "Use this editor binary", + &cli.StringFlag{ + Name: "editor", + Aliases: []string{"e"}, + Usage: "Use this editor binary", }, - cli.BoolFlag{ - Name: "create, c", - Usage: "Create a new secret if none found", + &cli.BoolFlag{ + Name: "create", + Aliases: []string{"c"}, + Usage: "Create a new secret if none found", }, }, }, @@ -363,13 +374,15 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com Aliases: []string{"search"}, BashComplete: func(c *cli.Context) { action.Complete(ctx, c) }, Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "clip, c", - Usage: "Copy the password into the clipboard", + &cli.BoolFlag{ + Name: "clip", + Aliases: []string{"c"}, + Usage: "Copy the password into the clipboard", }, - cli.BoolFlag{ - Name: "force, f", - Usage: "In the case of an exact match, display the password even if safecontent is enabled", + &cli.BoolFlag{ + Name: "force", + Aliases: []string{"f"}, + Usage: "In the case of an exact match, display the password even if safecontent is enabled", }, }, }, @@ -400,39 +413,48 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com }, BashComplete: func(c *cli.Context) { action.CompleteGenerate(ctx, c) }, Flags: []cli.Flag{ - cli.BoolTFlag{ - Name: "clip, c", - Usage: "Copy the generated password to the clipboard", - }, - cli.BoolFlag{ - Name: "print, p", - Usage: "Print the generated password to the terminal", - }, - cli.BoolFlag{ - Name: "force, f", - Usage: "Force to overwrite existing password", - }, - cli.BoolFlag{ - Name: "edit, e", - Usage: "Open secret for editing after generating a password", - }, - cli.BoolFlag{ - Name: "symbols, s", - Usage: "Use symbols in the password", - }, - cli.BoolFlag{ - Name: "xkcd, x", - Usage: "Use multiple random english words combined to a password. By default, space is used as separator and all words are lowercase", - }, - cli.StringFlag{ - Name: "xkcdsep, xs", - Usage: "Word separator for generated xkcd style password. If no separator is specified, the words are combined without spaces/separator and the first character of words is capitalised. This flag implies -xkcd", - Value: "", - }, - cli.StringFlag{ - Name: "xkcdlang, xl", - Usage: "Language to generate password from, currently de (german) and en (english, default) are supported", - Value: "en", + &cli.BoolFlag{ + Name: "clip", + Aliases: []string{"c"}, + Usage: "Copy the generated password to the clipboard", + Value: true, + }, + &cli.BoolFlag{ + Name: "print", + Aliases: []string{"p"}, + Usage: "Print the generated password to the terminal", + }, + &cli.BoolFlag{ + Name: "force", + Aliases: []string{"f"}, + Usage: "Force to overwrite existing password", + }, + &cli.BoolFlag{ + Name: "edit", + Aliases: []string{"e"}, + Usage: "Open secret for editing after generating a password", + }, + &cli.BoolFlag{ + Name: "symbols", + Aliases: []string{"s"}, + Usage: "Use symbols in the password", + }, + &cli.BoolFlag{ + Name: "xkcd", + Aliases: []string{"x"}, + Usage: "Use multiple random english words combined to a password. By default, space is used as separator and all words are lowercase", + }, + &cli.StringFlag{ + Name: "xkcdsep", + Aliases: []string{"xs"}, + Usage: "Word separator for generated xkcd style password. If no separator is specified, the words are combined without spaces/separator and the first character of words is capitalised. This flag implies -xkcd", + Value: "", + }, + &cli.StringFlag{ + Name: "xkcdlang", + Aliases: []string{"xl"}, + Usage: "Language to generate password from, currently de (german) and en (english, default) are supported", + Value: "en", }, }, }, @@ -442,7 +464,7 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com Description: "" + "This command allows you to cache your git-credentials with gopass." + "Activate by using `git config --global credential.helper \"!gopass git-credential $@\"`", - Subcommands: []cli.Command{ + Subcommands: []*cli.Command{ { Name: "get", Hidden: true, @@ -480,15 +502,15 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com return action.GitCredentialConfigure(withGlobalFlags(ctx, c), c) }, Flags: []cli.Flag{ - cli.BoolFlag{ + &cli.BoolFlag{ Name: "global", Usage: "Install for current user", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "local", Usage: "Install for current repository only", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "system", Usage: "Install for all users, requires superuser rights", }, @@ -501,7 +523,7 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com Usage: "Run and configure gopass as jsonapi e.g. for browser plugins", Description: "Setup and run gopass as native messaging hosts, e.g. for browser plugins.", Hidden: false, - Subcommands: []cli.Command{ + Subcommands: []*cli.Command{ { Name: "listen", Usage: "Listen and respond to messages via stdin/stdout", @@ -519,33 +541,34 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com return action.SetupNativeMessaging(withGlobalFlags(ctx, c), c) }, Flags: []cli.Flag{ - cli.StringFlag{ + &cli.StringFlag{ Name: "browser", Usage: "One of 'chrome' and 'firefox'", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "path", Usage: "Path to install 'gopass_wrapper.sh' to", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "manifest-path", Usage: "Path to install 'com.justwatch.gopass.json' to", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "global", Usage: "Install for all users, requires superuser rights", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "libpath", Usage: "Library path for global installation on linux. Default is /usr/lib", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "gopass-path", Usage: "Path to gopass binary. Default is auto detected", }, - cli.BoolTFlag{ + &cli.BoolFlag{ Name: "print", Usage: "Print installation summary before creating any files", + Value: true, }, }, }, @@ -564,17 +587,20 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com }, BashComplete: func(c *cli.Context) { action.Complete(ctx, c) }, Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "clip, c", - Usage: "Copy the time-based token into the clipboard", + &cli.BoolFlag{ + Name: "clip", + Aliases: []string{"c"}, + Usage: "Copy the time-based token into the clipboard", }, - cli.StringFlag{ - Name: "qr, q", - Usage: "Write QR code to FILE", + &cli.StringFlag{ + Name: "qr", + Aliases: []string{"q"}, + Usage: "Write QR code to FILE", }, - cli.BoolFlag{ - Name: "password, o", - Usage: "Only display the token", + &cli.BoolFlag{ + Name: "password", + Aliases: []string{"o"}, + Usage: "Only display the token", }, }, }, @@ -584,7 +610,7 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com Description: "" + "If the password store is a git repository, execute a git command " + "specified by git-command-args.", - Subcommands: []cli.Command{ + Subcommands: []*cli.Command{ { Name: "init", Usage: "Init git repo", @@ -594,15 +620,15 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com return action.GitInit(withGlobalFlags(ctx, c), c) }, Flags: []cli.Flag{ - cli.StringFlag{ + &cli.StringFlag{ Name: "store", Usage: "Store to operate on", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "sign-key", Usage: "GPG Key to sign commits", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "rcs", Usage: "Select sync backend (git, gitcli, gogit, noop)", }, @@ -613,7 +639,7 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com Usage: "Manage git remotes", Description: "These subcommands can be used to manage git remotes", Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) }, - Subcommands: []cli.Command{ + Subcommands: []*cli.Command{ { Name: "add", Usage: "Add git remote", @@ -623,7 +649,7 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com return action.GitAddRemote(withGlobalFlags(ctx, c), c) }, Flags: []cli.Flag{ - cli.StringFlag{ + &cli.StringFlag{ Name: "store", Usage: "Store to operate on", }, @@ -638,7 +664,7 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com return action.GitRemoveRemote(withGlobalFlags(ctx, c), c) }, Flags: []cli.Flag{ - cli.StringFlag{ + &cli.StringFlag{ Name: "store", Usage: "Store to operate on", }, @@ -655,7 +681,7 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com return action.GitPush(withGlobalFlags(ctx, c), c) }, Flags: []cli.Flag{ - cli.StringFlag{ + &cli.StringFlag{ Name: "store", Usage: "Store to operate on", }, @@ -670,7 +696,7 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com return action.GitPull(withGlobalFlags(ctx, c), c) }, Flags: []cli.Flag{ - cli.StringFlag{ + &cli.StringFlag{ Name: "store", Usage: "Store to operate on", }, @@ -685,7 +711,7 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com return action.GitStatus(withGlobalFlags(ctx, c), c) }, Flags: []cli.Flag{ - cli.StringFlag{ + &cli.StringFlag{ Name: "store", Usage: "Store to operate on", }, @@ -716,9 +742,10 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com }, BashComplete: func(c *cli.Context) { action.Complete(ctx, c) }, Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "password, p", - Usage: "Include passwords in output", + &cli.BoolFlag{ + Name: "password", + Aliases: []string{"p"}, + Usage: "Include passwords in output", }, }, }, @@ -731,23 +758,25 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com return action.Init(withGlobalFlags(ctx, c), c) }, Flags: []cli.Flag{ - cli.StringFlag{ - Name: "path, p", - Usage: "Set the sub-store path to operate on", + &cli.StringFlag{ + Name: "path", + Aliases: []string{"p"}, + Usage: "Set the sub-store path to operate on", }, - cli.StringFlag{ - Name: "store, s", - Usage: "Set the name of the sub-store", + &cli.StringFlag{ + Name: "store", + Aliases: []string{"s"}, + Usage: "Set the name of the sub-store", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "crypto", Usage: "Select crypto backend (gpg, gpgcli, plain, xc)", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "rcs", Usage: "Select sync backend (git, gitcli, gogit, noop)", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "nogit", Usage: "(DEPRECATED): Select noop RCS backend. Use '--rcs noop' instead", Hidden: true, @@ -767,21 +796,25 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com }, BashComplete: func(c *cli.Context) { action.Complete(ctx, c) }, Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "echo, e", - Usage: "Display secret while typing", - }, - cli.BoolFlag{ - Name: "multiline, m", - Usage: "Insert using $EDITOR", - }, - cli.BoolFlag{ - Name: "force, f", - Usage: "Overwrite any existing secret and do not prompt to confirm recipients", - }, - cli.BoolFlag{ - Name: "append, a", - Usage: "Append to any existing data", + &cli.BoolFlag{ + Name: "echo", + Aliases: []string{"e"}, + Usage: "Display secret while typing", + }, + &cli.BoolFlag{ + Name: "multiline", + Aliases: []string{"m"}, + Usage: "Insert using $EDITOR", + }, + &cli.BoolFlag{ + Name: "force", + Aliases: []string{"f"}, + Usage: "Overwrite any existing secret and do not prompt to confirm recipients", + }, + &cli.BoolFlag{ + Name: "append", + Aliases: []string{"a"}, + Usage: "Append to any existing data", }, }, }, @@ -798,21 +831,25 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com }, BashComplete: func(c *cli.Context) { action.Complete(ctx, c) }, Flags: []cli.Flag{ - cli.IntFlag{ - Name: "limit, l", - Usage: "Max tree depth", - }, - cli.BoolFlag{ - Name: "flat, f", - Usage: "Print flat list", - }, - cli.BoolFlag{ - Name: "folders, fo", - Usage: "Print flat list of folders", - }, - cli.BoolFlag{ - Name: "strip-prefix, s", - Usage: "Strip prefix from filtered entries", + &cli.IntFlag{ + Name: "limit", + Aliases: []string{"l"}, + Usage: "Max tree depth", + }, + &cli.BoolFlag{ + Name: "flat", + Aliases: []string{"f"}, + Usage: "Print flat list", + }, + &cli.BoolFlag{ + Name: "folders", + Aliases: []string{"fo"}, + Usage: "Print flat list of folders", + }, + &cli.BoolFlag{ + Name: "strip-prefix", + Aliases: []string{"s"}, + Usage: "Strip prefix from filtered entries", }, }, }, @@ -831,9 +868,10 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com }, BashComplete: func(c *cli.Context) { action.Complete(ctx, c) }, Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "force, f", - Usage: "Force to move the secret and overwrite existing one", + &cli.BoolFlag{ + Name: "force", + Aliases: []string{"f"}, + Usage: "Force to move the secret and overwrite existing one", }, }, }, @@ -847,7 +885,7 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com Action: func(c *cli.Context) error { return action.MountsPrint(withGlobalFlags(ctx, c), c) }, - Subcommands: []cli.Command{ + Subcommands: []*cli.Command{ { Name: "add", Aliases: []string{"mount"}, @@ -860,9 +898,10 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com return action.MountAdd(withGlobalFlags(ctx, c), c) }, Flags: []cli.Flag{ - cli.StringFlag{ - Name: "init, i", - Usage: "Init the store with the given recipient key", + &cli.StringFlag{ + Name: "init", + Aliases: []string{"i"}, + Usage: "Init the store with the given recipient key", }, }, }, @@ -891,7 +930,7 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com Action: func(c *cli.Context) error { return action.RecipientsPrint(withGlobalFlags(ctx, c), c) }, - Subcommands: []cli.Command{ + Subcommands: []*cli.Command{ { Name: "add", Aliases: []string{"authorize"}, @@ -907,11 +946,11 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com return action.RecipientsAdd(withGlobalFlags(ctx, c), c) }, Flags: []cli.Flag{ - cli.StringFlag{ + &cli.StringFlag{ Name: "store", Usage: "Store to operate on", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "force", Usage: "Force adding non-existing keys", }, @@ -938,11 +977,11 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com action.RecipientsComplete(ctx, c) }, Flags: []cli.Flag{ - cli.StringFlag{ + &cli.StringFlag{ Name: "store", Usage: "Store to operate on", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "force", Usage: "Force adding non-existing keys", }, @@ -973,31 +1012,31 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com return action.InitOnboarding(withGlobalFlags(ctx, c), c) }, Flags: []cli.Flag{ - cli.StringFlag{ + &cli.StringFlag{ Name: "remote", Usage: "URL to a git remote, will attempt to join this team", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "alias", Usage: "Local mount point for the given remote", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "create", Usage: "Create a new team (default: false, i.e. join an existing team)", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "name", Usage: "Firstname and Lastname for unattended GPG key generation", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "email", Usage: "EMail for unattended GPG key generation", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "crypto", Usage: "Select crypto backend (gpg, gpgcli, plain, xc)", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "rcs", Usage: "Select sync backend (git, gitcli, gogit, noop)", }, @@ -1015,27 +1054,31 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com }, BashComplete: func(c *cli.Context) { action.Complete(ctx, c) }, Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "clip, c", - Usage: "Copy the first line of the secret into the clipboard", + &cli.BoolFlag{ + Name: "clip", + Aliases: []string{"c"}, + Usage: "Copy the first line of the secret into the clipboard", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "qr", Usage: "Print the first line of the secret as QR Code", }, - cli.BoolFlag{ - Name: "force, f", - Usage: "Display the password even if safecontent is enabled", + &cli.BoolFlag{ + Name: "force", + Aliases: []string{"f"}, + Usage: "Display the password even if safecontent is enabled", }, - cli.BoolFlag{ - Name: "password, o", - Usage: "Display only the password", + &cli.BoolFlag{ + Name: "password", + Aliases: []string{"o"}, + Usage: "Display only the password", }, - cli.BoolFlag{ - Name: "sync, s", - Usage: "Sync before attempting to display the secret", + &cli.BoolFlag{ + Name: "sync", + Aliases: []string{"s"}, + Usage: "Sync before attempting to display the secret", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "revision", Usage: "Show a past revision", }, @@ -1053,9 +1096,10 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com }, Flags: []cli.Flag{ - cli.StringFlag{ - Name: "store, s", - Usage: "Select the store to sync", + &cli.StringFlag{ + Name: "store", + Aliases: []string{"s"}, + Usage: "Select the store to sync", }, }, }, @@ -1069,7 +1113,7 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com Action: func(c *cli.Context) error { return action.TemplatesPrint(withGlobalFlags(ctx, c), c) }, - Subcommands: []cli.Command{ + Subcommands: []*cli.Command{ { Name: "show", Usage: "Show a secret template.", @@ -1114,11 +1158,11 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com }, Hidden: true, Flags: []cli.Flag{ - cli.IntFlag{ + &cli.IntFlag{ Name: "timeout", Usage: "Time to wait", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "force", Usage: "Clear clipboard even if checksum mismatches", }, @@ -1134,7 +1178,7 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com return action.Update(withGlobalFlags(ctx, c), c) }, Flags: []cli.Flag{ - cli.BoolFlag{ + &cli.BoolFlag{ Name: "pre", Usage: "Update to prereleases", }, @@ -1157,7 +1201,7 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com Description: "" + "These subcommands are used to control and test the experimental crypto" + "implementation.", - Subcommands: []cli.Command{ + Subcommands: []*cli.Command{ { Name: "list-private-keys", Action: func(c *cli.Context) error { @@ -1182,10 +1226,10 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com return xc.ExportPublicKey(withGlobalFlags(ctx, c), c) }, Flags: []cli.Flag{ - cli.StringFlag{ + &cli.StringFlag{ Name: "id", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "file", }, }, @@ -1196,10 +1240,10 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com return xc.ImportPublicKey(withGlobalFlags(ctx, c), c) }, Flags: []cli.Flag{ - cli.StringFlag{ + &cli.StringFlag{ Name: "id", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "file", }, }, @@ -1210,10 +1254,10 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com return xc.ExportPrivateKey(withGlobalFlags(ctx, c), c) }, Flags: []cli.Flag{ - cli.StringFlag{ + &cli.StringFlag{ Name: "id", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "file", }, }, @@ -1224,10 +1268,10 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com return xc.ImportPrivateKey(withGlobalFlags(ctx, c), c) }, Flags: []cli.Flag{ - cli.StringFlag{ + &cli.StringFlag{ Name: "id", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "file", }, }, @@ -1238,7 +1282,7 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com return xc.RemoveKey(withGlobalFlags(ctx, c), c) }, Flags: []cli.Flag{ - cli.StringFlag{ + &cli.StringFlag{ Name: "id", }, }, @@ -1249,13 +1293,13 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com return xc.EncryptFile(withGlobalFlags(ctx, c), c) }, Flags: []cli.Flag{ - cli.StringFlag{ + &cli.StringFlag{ Name: "file", }, - cli.StringSliceFlag{ + &cli.StringSliceFlag{ Name: "recipients", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "stream", }, }, @@ -1266,10 +1310,10 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com return xc.DecryptFile(withGlobalFlags(ctx, c), c) }, Flags: []cli.Flag{ - cli.StringFlag{ + &cli.StringFlag{ Name: "file", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "stream", }, }, diff --git a/commands_test.go b/commands_test.go index 60be79d744..3bfead794a 100644 --- a/commands_test.go +++ b/commands_test.go @@ -17,7 +17,7 @@ import ( "github.com/gopasspw/gopass/pkg/out" "github.com/gopasspw/gopass/tests/gptest" "github.com/stretchr/testify/assert" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // commandsWithError is a list of commands that return an error when @@ -95,7 +95,7 @@ func TestGetCommands(t *testing.T) { testCommands(t, c, commands, prefix) } -func testCommands(t *testing.T, c *cli.Context, commands []cli.Command, prefix string) { +func testCommands(t *testing.T, c *cli.Context, commands []*cli.Command, prefix string) { for _, cmd := range commands { if cmd.Name == "agent" || cmd.Name == "update" { // the agent command is blocking @@ -118,13 +118,11 @@ func testCommands(t *testing.T, c *cli.Context, commands []cli.Command, prefix s } if cmd.Action != nil { fullName := prefix + "." + cmd.Name - if av, ok := cmd.Action.(func(c *cli.Context) error); ok { - if _, found := commandsWithError[fullName]; found { - assert.Error(t, av(c), fullName) - continue - } - assert.NoError(t, av(c), fullName) + if _, found := commandsWithError[fullName]; found { + assert.Error(t, cmd.Action(c), fullName) + continue } + assert.NoError(t, cmd.Action(c), fullName) } } } diff --git a/go.mod b/go.mod index 7217a89ec1..2bd2743506 100644 --- a/go.mod +++ b/go.mod @@ -50,6 +50,7 @@ require ( github.com/skip2/go-qrcode v0.0.0-20191027152451-9434209cb086 github.com/stretchr/testify v1.4.0 github.com/urfave/cli v1.22.2 + github.com/urfave/cli/v2 v2.2.0 github.com/xrash/smetrics v0.0.0-20170218160415-a3153f7040e9 // indirect golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 golang.org/x/net v0.0.0-20200301022130-244492dfa37a diff --git a/go.sum b/go.sum index c19f4e7834..7885cf5e6f 100644 --- a/go.sum +++ b/go.sum @@ -268,6 +268,9 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= 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/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4= +github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70= github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4= github.com/xrash/smetrics v0.0.0-20170218160415-a3153f7040e9 h1:w8V9v0qVympSF6GjdjIyeqR7+EVhAF9CBQmkmW7Zw0w= diff --git a/main.go b/main.go index f14e25c938..36944173a4 100644 --- a/main.go +++ b/main.go @@ -19,7 +19,7 @@ import ( "github.com/blang/semver" "github.com/fatih/color" colorable "github.com/mattn/go-colorable" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) const ( @@ -110,7 +110,7 @@ func (e errorWriter) Write(p []byte) (int, error) { } func withGlobalFlags(ctx context.Context, c *cli.Context) context.Context { - if c.GlobalBool("yes") { + if c.Bool("yes") { ctx = ctxutil.WithAlwaysYes(ctx, true) } return ctx diff --git a/main_test.go b/main_test.go index 78d0d6f3c6..124a21c783 100644 --- a/main_test.go +++ b/main_test.go @@ -11,7 +11,7 @@ import ( "github.com/blang/semver" "github.com/gopasspw/gopass/pkg/ctxutil" "github.com/stretchr/testify/assert" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestGlobalFlags(t *testing.T) { @@ -23,7 +23,7 @@ func TestGlobalFlags(t *testing.T) { Name: "yes", Usage: "yes", } - assert.NoError(t, sf.ApplyWithError(fs)) + assert.NoError(t, sf.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--yes"})) c := cli.NewContext(app, fs, nil) diff --git a/pkg/action/audit.go b/pkg/action/audit.go index 24779b7742..47c834e555 100644 --- a/pkg/action/audit.go +++ b/pkg/action/audit.go @@ -6,7 +6,7 @@ import ( "github.com/gopasspw/gopass/pkg/audit" "github.com/gopasspw/gopass/pkg/out" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // Audit validates passwords against common flaws diff --git a/pkg/action/audit_test.go b/pkg/action/audit_test.go index 40854895f6..560e4531c0 100644 --- a/pkg/action/audit_test.go +++ b/pkg/action/audit_test.go @@ -14,7 +14,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestAudit(t *testing.T) { diff --git a/pkg/action/binary/binary_test.go b/pkg/action/binary/binary_test.go index d0aa39d61d..a6c426f849 100644 --- a/pkg/action/binary/binary_test.go +++ b/pkg/action/binary/binary_test.go @@ -15,7 +15,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestBinary(t *testing.T) { diff --git a/pkg/action/binary/cat.go b/pkg/action/binary/cat.go index 6217ad7eb9..1a035ffa98 100644 --- a/pkg/action/binary/cat.go +++ b/pkg/action/binary/cat.go @@ -13,7 +13,7 @@ import ( "github.com/gopasspw/gopass/pkg/store/secret" "github.com/gopasspw/gopass/pkg/store/sub" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // Cat prints to or reads from STDIN/STDOUT diff --git a/pkg/action/binary/copy.go b/pkg/action/binary/copy.go index 1b0d594bcf..bfd7566e85 100644 --- a/pkg/action/binary/copy.go +++ b/pkg/action/binary/copy.go @@ -14,7 +14,7 @@ import ( "github.com/gopasspw/gopass/pkg/store/sub" "github.com/pkg/errors" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // Copy copies either from the filesystem to the store or from the store diff --git a/pkg/action/binary/sum.go b/pkg/action/binary/sum.go index a113f90173..81918149fd 100644 --- a/pkg/action/binary/sum.go +++ b/pkg/action/binary/sum.go @@ -8,7 +8,7 @@ import ( "github.com/gopasspw/gopass/pkg/action" "github.com/gopasspw/gopass/pkg/out" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // Sum decodes binary content and computes the SHA256 checksum diff --git a/pkg/action/clihelper.go b/pkg/action/clihelper.go index 0f8b8ae47d..a061572db9 100644 --- a/pkg/action/clihelper.go +++ b/pkg/action/clihelper.go @@ -5,7 +5,7 @@ import ( "strings" "github.com/gopasspw/gopass/pkg/cui" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // ConfirmRecipients asks the user to confirm a given set of recipients @@ -23,10 +23,10 @@ func (a argList) Get(n int) string { } func parseArgs(c *cli.Context) (argList, map[string]string) { - args := make(argList, 0, len(c.Args())) - kvps := make(map[string]string, len(c.Args())) + args := make(argList, 0, c.Args().Len()) + kvps := make(map[string]string, c.Args().Len()) OUTER: - for _, arg := range c.Args() { + for _, arg := range c.Args().Slice() { for _, sep := range []string{":", "="} { if !strings.Contains(arg, sep) { continue diff --git a/pkg/action/clihelper_test.go b/pkg/action/clihelper_test.go index 117e5fb6b4..8757cb750c 100644 --- a/pkg/action/clihelper_test.go +++ b/pkg/action/clihelper_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestParseArgs(t *testing.T) { diff --git a/pkg/action/clone.go b/pkg/action/clone.go index 4a1f961457..ade66854b8 100644 --- a/pkg/action/clone.go +++ b/pkg/action/clone.go @@ -14,7 +14,7 @@ import ( "github.com/gopasspw/gopass/pkg/termio" "github.com/fatih/color" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // Clone will fetch and mount a new password store from a git repo @@ -26,14 +26,14 @@ func (s *Action) Clone(ctx context.Context, c *cli.Context) error { ctx = backend.WithRCSBackendString(ctx, c.String("sync")) } - if len(c.Args()) < 1 { + if c.Args().Len() < 1 { return ExitError(ctx, ExitUsage, nil, "Usage: %s clone repo [mount]", s.Name) } - repo := c.Args()[0] + repo := c.Args().Get(0) mount := "" - if len(c.Args()) > 1 { - mount = c.Args()[1] + if c.Args().Len() > 1 { + mount = c.Args().Get(1) } path := c.String("path") diff --git a/pkg/action/clone_test.go b/pkg/action/clone_test.go index 1887046d90..0b5614c788 100644 --- a/pkg/action/clone_test.go +++ b/pkg/action/clone_test.go @@ -20,7 +20,7 @@ import ( "github.com/blang/semver" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func aGitRepo(ctx context.Context, u *gptest.Unit, t *testing.T, name string) string { diff --git a/pkg/action/completion.go b/pkg/action/completion.go index 913e14f160..f9d6031d70 100644 --- a/pkg/action/completion.go +++ b/pkg/action/completion.go @@ -7,11 +7,9 @@ import ( "runtime" "strings" - fishcomp "github.com/gopasspw/gopass/pkg/completion/fish" zshcomp "github.com/gopasspw/gopass/pkg/completion/zsh" "github.com/gopasspw/gopass/pkg/out" - - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var escapeRegExp = regexp.MustCompile(`(\s|\(|\)|\<|\>|\&|\;|\#|\\|\||\*|\?)`) @@ -90,7 +88,10 @@ func (s *Action) CompletionBash(c *cli.Context) error { // CompletionFish returns an autocompletion script for fish func (s *Action) CompletionFish(c *cli.Context, a *cli.App) error { - comp, err := fishcomp.GetCompletion(a) + if a == nil { + return fmt.Errorf("app is nil") + } + comp, err := a.ToFishCompletion() if err != nil { return err } diff --git a/pkg/action/completion_test.go b/pkg/action/completion_test.go index 9551cd1a1a..96c0e56bc3 100644 --- a/pkg/action/completion_test.go +++ b/pkg/action/completion_test.go @@ -11,7 +11,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestBashEscape(t *testing.T) { @@ -39,7 +39,7 @@ func TestComplete(t *testing.T) { require.NotNil(t, act) app := cli.NewApp() - app.Commands = []cli.Command{ + app.Commands = []*cli.Command{ { Name: "test", Aliases: []string{"foo", "bar"}, diff --git a/pkg/action/config.go b/pkg/action/config.go index 58e5f7b9f3..4fb7753a80 100644 --- a/pkg/action/config.go +++ b/pkg/action/config.go @@ -8,26 +8,26 @@ import ( "github.com/gopasspw/gopass/pkg/out" "github.com/pkg/errors" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // Config handles changes to the gopass configuration func (s *Action) Config(ctx context.Context, c *cli.Context) error { - if len(c.Args()) < 1 { + if c.Args().Len() < 1 { s.printConfigValues(ctx, "") return nil } - if len(c.Args()) == 1 { - s.printConfigValues(ctx, "", c.Args()[0]) + if c.Args().Len() == 1 { + s.printConfigValues(ctx, "", c.Args().Get(0)) return nil } - if len(c.Args()) > 2 { + if c.Args().Len() > 2 { return ExitError(ctx, ExitUsage, nil, "Usage: %s config key value", s.Name) } - if err := s.setConfigValue(ctx, c.String("store"), c.Args()[0], c.Args()[1]); err != nil { + if err := s.setConfigValue(ctx, c.String("store"), c.Args().Get(0), c.Args().Get(1)); err != nil { return ExitError(ctx, ExitUnknown, err, "Error setting config value") } return nil diff --git a/pkg/action/config_test.go b/pkg/action/config_test.go index 0659ed001d..ff94fc41a5 100644 --- a/pkg/action/config_test.go +++ b/pkg/action/config_test.go @@ -15,7 +15,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestConfig(t *testing.T) { diff --git a/pkg/action/copy.go b/pkg/action/copy.go index cb771cff06..0085453776 100644 --- a/pkg/action/copy.go +++ b/pkg/action/copy.go @@ -6,19 +6,19 @@ import ( "github.com/gopasspw/gopass/pkg/termio" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // Copy the contents of a file to another one func (s *Action) Copy(ctx context.Context, c *cli.Context) error { force := c.Bool("force") - if len(c.Args()) != 2 { + if c.Args().Len() != 2 { return ExitError(ctx, ExitUsage, nil, "Usage: %s cp ", s.Name) } - from := c.Args()[0] - to := c.Args()[1] + from := c.Args().Get(0) + to := c.Args().Get(1) return s.copy(ctx, from, to, force) } diff --git a/pkg/action/copy_test.go b/pkg/action/copy_test.go index 368881d6de..47ddf0799a 100644 --- a/pkg/action/copy_test.go +++ b/pkg/action/copy_test.go @@ -14,7 +14,7 @@ import ( "github.com/fatih/color" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestCopy(t *testing.T) { diff --git a/pkg/action/create/create.go b/pkg/action/create/create.go index 43681a116c..33d222f8c4 100644 --- a/pkg/action/create/create.go +++ b/pkg/action/create/create.go @@ -21,7 +21,7 @@ import ( "github.com/gopasspw/gopass/pkg/store/sub" "github.com/gopasspw/gopass/pkg/termio" "github.com/martinhoefling/goxkcdpwgen/xkcdpwgen" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) const ( diff --git a/pkg/action/create/create_test.go b/pkg/action/create/create_test.go index f7a47f86d2..b73fbcb474 100644 --- a/pkg/action/create/create_test.go +++ b/pkg/action/create/create_test.go @@ -16,7 +16,7 @@ import ( "github.com/gopasspw/gopass/pkg/termio" "github.com/gopasspw/gopass/tests/mockstore" "github.com/stretchr/testify/assert" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestExtractHostname(t *testing.T) { @@ -90,7 +90,7 @@ y Name: "print", Usage: "print", } - assert.NoError(t, sf.ApplyWithError(fs)) + assert.NoError(t, sf.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--print=true"})) c := cli.NewContext(app, fs, nil) diff --git a/pkg/action/delete.go b/pkg/action/delete.go index d8727f25c8..a66ef159a2 100644 --- a/pkg/action/delete.go +++ b/pkg/action/delete.go @@ -7,7 +7,7 @@ import ( "github.com/gopasspw/gopass/pkg/store/sub" "github.com/gopasspw/gopass/pkg/termio" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // Delete a secret file with its content diff --git a/pkg/action/delete_test.go b/pkg/action/delete_test.go index 3d3397f0e4..7f0efae6a7 100644 --- a/pkg/action/delete_test.go +++ b/pkg/action/delete_test.go @@ -16,7 +16,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestDelete(t *testing.T) { @@ -75,7 +75,7 @@ func TestDelete(t *testing.T) { Name: "recursive", Usage: "recursive", } - assert.NoError(t, sf.ApplyWithError(fs)) + assert.NoError(t, sf.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--recursive=true", "foo"})) c = cli.NewContext(app, fs, nil) diff --git a/pkg/action/edit.go b/pkg/action/edit.go index 1b1f3f5ea8..dadc38345a 100644 --- a/pkg/action/edit.go +++ b/pkg/action/edit.go @@ -13,7 +13,7 @@ import ( "github.com/gopasspw/gopass/pkg/store/secret" "github.com/gopasspw/gopass/pkg/store/sub" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // Edit the content of a password file diff --git a/pkg/action/edit_test.go b/pkg/action/edit_test.go index e80609f22d..7bac50a0cb 100644 --- a/pkg/action/edit_test.go +++ b/pkg/action/edit_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestEdit(t *testing.T) { diff --git a/pkg/action/errors.go b/pkg/action/errors.go index a7130de26e..d8a93c465a 100644 --- a/pkg/action/errors.go +++ b/pkg/action/errors.go @@ -6,7 +6,7 @@ import ( "github.com/gopasspw/gopass/pkg/out" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) const ( diff --git a/pkg/action/find.go b/pkg/action/find.go index e7dcfd3205..a0e0b0d5b6 100644 --- a/pkg/action/find.go +++ b/pkg/action/find.go @@ -11,7 +11,7 @@ import ( "github.com/gopasspw/gopass/pkg/out" "github.com/schollz/closestmatch" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // Find a string in the secret file's name diff --git a/pkg/action/find_test.go b/pkg/action/find_test.go index 88863bfa60..e112264f4c 100644 --- a/pkg/action/find_test.go +++ b/pkg/action/find_test.go @@ -18,7 +18,7 @@ import ( "github.com/fatih/color" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestFind(t *testing.T) { @@ -77,7 +77,7 @@ func TestFind(t *testing.T) { Name: "clip", Usage: "clip", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) assert.NoError(t, fs.Parse([]string{"-clip", "fo"})) c = cli.NewContext(app, fs, nil) @@ -93,7 +93,7 @@ func TestFind(t *testing.T) { Name: "force", Usage: "force", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) assert.NoError(t, fs.Parse([]string{"-force", "fo"})) c = cli.NewContext(app, fs, nil) diff --git a/pkg/action/fsck.go b/pkg/action/fsck.go index a40c6900ae..33a50c7227 100644 --- a/pkg/action/fsck.go +++ b/pkg/action/fsck.go @@ -13,7 +13,7 @@ import ( "github.com/gopasspw/gopass/pkg/out" "github.com/muesli/goprogressbar" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // Fsck checks the store integrity diff --git a/pkg/action/fsck_test.go b/pkg/action/fsck_test.go index 35f8bc74d3..fd3c846fb8 100644 --- a/pkg/action/fsck_test.go +++ b/pkg/action/fsck_test.go @@ -16,7 +16,7 @@ import ( "github.com/fatih/color" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestFsck(t *testing.T) { diff --git a/pkg/action/generate.go b/pkg/action/generate.go index 3ebb11f387..3ab14a6134 100644 --- a/pkg/action/generate.go +++ b/pkg/action/generate.go @@ -20,7 +20,7 @@ import ( "github.com/gopasspw/gopass/pkg/termio" "github.com/fatih/color" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) const ( @@ -265,11 +265,10 @@ func setMetadata(sec store.Secret, kvps map[string]string) { // CompleteGenerate implements the completion heuristic for the generate command func (s *Action) CompleteGenerate(ctx context.Context, c *cli.Context) { - args := c.Args() - if len(args) < 1 { + if c.Args().Len() < 1 { return } - needle := args[0] + needle := c.Args().Get(0) _, err := s.Store.Initialized(ctx) // important to make sure the structs are not nil if err != nil { diff --git a/pkg/action/generate_test.go b/pkg/action/generate_test.go index 41a02c1a20..dc4da0f741 100644 --- a/pkg/action/generate_test.go +++ b/pkg/action/generate_test.go @@ -16,7 +16,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestGenerate(t *testing.T) { @@ -66,7 +66,7 @@ func TestGenerate(t *testing.T) { Name: "force", Usage: "force", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--force=true", "foobar"})) c = cli.NewContext(app, fs, nil) @@ -79,7 +79,7 @@ func TestGenerate(t *testing.T) { Name: "force", Usage: "force", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--force=true", "foobar", "32"})) c = cli.NewContext(app, fs, nil) @@ -92,17 +92,17 @@ func TestGenerate(t *testing.T) { Name: "force", Usage: "force", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) bf = cli.BoolFlag{ Name: "symbols", Usage: "symbols", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) bf = cli.BoolFlag{ Name: "print", Usage: "print", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--force=true", "--print=true", "--symbols", "foobar", "32"})) c = cli.NewContext(app, fs, nil) @@ -116,17 +116,17 @@ func TestGenerate(t *testing.T) { Name: "force", Usage: "force", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) bf = cli.BoolFlag{ Name: "symbols", Usage: "symbols", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) bf = cli.BoolFlag{ Name: "print", Usage: "print", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--force=true", "--print=true", "--symbols=true", "foobar", "32"})) c = cli.NewContext(app, fs, nil) @@ -140,17 +140,17 @@ func TestGenerate(t *testing.T) { Name: "force", Usage: "force", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) bf = cli.BoolFlag{ Name: "symbols", Usage: "symbols", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) bf = cli.BoolFlag{ Name: "print", Usage: "print", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--force=true", "--print=true", "--symbols=false", "foobar", "32"})) c = cli.NewContext(app, fs, nil) @@ -164,18 +164,18 @@ func TestGenerate(t *testing.T) { Name: "force", Usage: "force", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) bf = cli.BoolFlag{ Name: "xkcd", Usage: "xkcd", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) sf := cli.StringFlag{ Name: "xkcdlang", Usage: "xkcdlange", Value: "en", } - assert.NoError(t, sf.ApplyWithError(fs)) + assert.NoError(t, sf.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--force=true", "--xkcd=true", "foobar", "32"})) c = cli.NewContext(app, fs, nil) @@ -188,18 +188,18 @@ func TestGenerate(t *testing.T) { Name: "force", Usage: "force", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) bf = cli.BoolFlag{ Name: "xkcd", Usage: "xkcd", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) sf = cli.StringFlag{ Name: "xkcdlang", Usage: "xkcdlange", Value: "en", } - assert.NoError(t, sf.ApplyWithError(fs)) + assert.NoError(t, sf.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--force=true", "--xkcd=true", "foobar", "baz", "32"})) c = cli.NewContext(app, fs, nil) @@ -212,18 +212,18 @@ func TestGenerate(t *testing.T) { Name: "force", Usage: "force", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) bf = cli.BoolFlag{ Name: "xkcd", Usage: "xkcd", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) sf = cli.StringFlag{ Name: "xkcdlang", Usage: "xkcdlange", Value: "en", } - assert.NoError(t, sf.ApplyWithError(fs)) + assert.NoError(t, sf.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--force=true", "--xkcd=true", "foobar", "baz"})) c = cli.NewContext(app, fs, nil) @@ -236,23 +236,23 @@ func TestGenerate(t *testing.T) { Name: "force", Usage: "force", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) bf = cli.BoolFlag{ Name: "xkcd", Usage: "xkcd", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) bf = cli.BoolFlag{ Name: "print", Usage: "print", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) sf = cli.StringFlag{ Name: "xkcdlang", Usage: "xkcdlange", Value: "en", } - assert.NoError(t, sf.ApplyWithError(fs)) + assert.NoError(t, sf.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--force=true", "--print=true", "--xkcd=true", "foobar", "baz"})) c = cli.NewContext(app, fs, nil) diff --git a/pkg/action/git-credential.go b/pkg/action/git-credential.go index 0346bc8ae4..e974bde515 100644 --- a/pkg/action/git-credential.go +++ b/pkg/action/git-credential.go @@ -16,7 +16,7 @@ import ( "github.com/gopasspw/gopass/pkg/store/secret" "github.com/gopasspw/gopass/pkg/store/sub" "github.com/gopasspw/gopass/pkg/termio" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) type gitCredentials struct { diff --git a/pkg/action/git-credential_test.go b/pkg/action/git-credential_test.go index b38cd39416..08607eb25f 100644 --- a/pkg/action/git-credential_test.go +++ b/pkg/action/git-credential_test.go @@ -17,7 +17,7 @@ import ( "github.com/gopasspw/gopass/tests/gptest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestGitCredentialFormat(t *testing.T) { diff --git a/pkg/action/git.go b/pkg/action/git.go index 957d6d2094..d1bf79849b 100644 --- a/pkg/action/git.go +++ b/pkg/action/git.go @@ -11,7 +11,7 @@ import ( "github.com/fatih/color" "github.com/pkg/errors" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // GitInit initializes a git repo including basic configuration diff --git a/pkg/action/git_test.go b/pkg/action/git_test.go index 9cd54e6aef..c82d3ba392 100644 --- a/pkg/action/git_test.go +++ b/pkg/action/git_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestGit(t *testing.T) { @@ -44,12 +44,12 @@ func TestGit(t *testing.T) { Name: "username", Usage: "username", } - assert.NoError(t, un.ApplyWithError(fs)) + assert.NoError(t, un.Apply(fs)) ue := cli.StringFlag{ Name: "useremail", Usage: "useremail", } - assert.NoError(t, ue.ApplyWithError(fs)) + assert.NoError(t, ue.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--username", "foobar", "--useremail", "foo.bar@example.org"})) c := cli.NewContext(app, fs, nil) diff --git a/pkg/action/grep.go b/pkg/action/grep.go index 78703ab8a7..6b2643bdd0 100644 --- a/pkg/action/grep.go +++ b/pkg/action/grep.go @@ -7,7 +7,7 @@ import ( "github.com/gopasspw/gopass/pkg/out" "github.com/fatih/color" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // Grep searches a string inside the content of all files diff --git a/pkg/action/grep_test.go b/pkg/action/grep_test.go index e53ed9261f..162fa641cc 100644 --- a/pkg/action/grep_test.go +++ b/pkg/action/grep_test.go @@ -14,7 +14,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestGrep(t *testing.T) { diff --git a/pkg/action/hibp.go b/pkg/action/hibp.go index ddbefe3342..d11e3e57a7 100644 --- a/pkg/action/hibp.go +++ b/pkg/action/hibp.go @@ -15,7 +15,7 @@ import ( "github.com/fatih/color" "github.com/muesli/goprogressbar" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // HIBP compares all entries from the store against the provided SHA1 sum dumps diff --git a/pkg/action/hibp_test.go b/pkg/action/hibp_test.go index bc81281546..cd68fffb9d 100644 --- a/pkg/action/hibp_test.go +++ b/pkg/action/hibp_test.go @@ -21,7 +21,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) const testHibpSample = `000000005AD76BD555C1D6D771DE417A4B87E4B4 @@ -67,7 +67,7 @@ func TestHIBPDump(t *testing.T) { Name: "dumps", Usage: "dumps", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--dumps=" + fn})) c = cli.NewContext(app, fs, nil) @@ -82,7 +82,7 @@ func TestHIBPDump(t *testing.T) { Name: "dumps", Usage: "dumps", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--dumps=" + fn})) c = cli.NewContext(app, fs, nil) assert.NoError(t, testWriteGZ(fn, []byte(testHibpSample))) @@ -131,7 +131,7 @@ func TestHIBPAPI(t *testing.T) { Name: "api", Usage: "api", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--api=true"})) c := cli.NewContext(app, fs, nil) diff --git a/pkg/action/history.go b/pkg/action/history.go index 8c70806443..0861ea11b0 100644 --- a/pkg/action/history.go +++ b/pkg/action/history.go @@ -6,7 +6,7 @@ import ( "github.com/gopasspw/gopass/pkg/out" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // History displays the history of a given secret diff --git a/pkg/action/history_test.go b/pkg/action/history_test.go index 6d62dc1e52..59f883c08d 100644 --- a/pkg/action/history_test.go +++ b/pkg/action/history_test.go @@ -16,7 +16,7 @@ import ( "github.com/blang/semver" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestHistory(t *testing.T) { @@ -70,7 +70,7 @@ func TestHistory(t *testing.T) { Name: "password", Usage: "password", } - assert.NoError(t, sf.ApplyWithError(fs)) + assert.NoError(t, sf.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--password=true", "bar"})) c = cli.NewContext(app, fs, nil) diff --git a/pkg/action/init.go b/pkg/action/init.go index 20f90ffe36..560a104cbd 100644 --- a/pkg/action/init.go +++ b/pkg/action/init.go @@ -17,7 +17,7 @@ import ( "github.com/fatih/color" "github.com/pkg/errors" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // Initialized returns an error if the store is not properly @@ -59,7 +59,7 @@ func (s *Action) Init(ctx context.Context, c *cli.Context) error { out.Error(ctx, "WARNING: Store is already initialized") } - if err := s.init(ctx, alias, path, c.Args()...); err != nil { + if err := s.init(ctx, alias, path, c.Args().Slice()...); err != nil { return ExitError(ctx, ExitUnknown, err, "failed to initialize store: %s", err) } return nil diff --git a/pkg/action/init_test.go b/pkg/action/init_test.go index f5ede44fb8..69899a2f1b 100644 --- a/pkg/action/init_test.go +++ b/pkg/action/init_test.go @@ -17,7 +17,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestInit(t *testing.T) { @@ -119,17 +119,17 @@ func TestInitParseContext(t *testing.T) { Name: "crypto", Usage: "crypto", } - assert.NoError(t, sf.ApplyWithError(fs)) + assert.NoError(t, sf.Apply(fs)) sf = cli.StringFlag{ Name: "rcs", Usage: "rcs", } - assert.NoError(t, sf.ApplyWithError(fs)) + assert.NoError(t, sf.Apply(fs)) bf := cli.BoolFlag{ Name: "nogit", Usage: "nogit", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) assert.NoError(t, fs.Parse(tc.args), tc.name) c := cli.NewContext(app, fs, nil) assert.NoError(t, tc.check(initParseContext(context.Background(), c)), tc.name) diff --git a/pkg/action/insert.go b/pkg/action/insert.go index eb9ccbfdeb..80497c5be3 100644 --- a/pkg/action/insert.go +++ b/pkg/action/insert.go @@ -16,7 +16,7 @@ import ( "github.com/gopasspw/gopass/pkg/store/sub" "github.com/gopasspw/gopass/pkg/termio" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // Insert a string as content to a secret file diff --git a/pkg/action/insert_test.go b/pkg/action/insert_test.go index a8cda0a334..46c03661b2 100644 --- a/pkg/action/insert_test.go +++ b/pkg/action/insert_test.go @@ -14,7 +14,7 @@ import ( "github.com/fatih/color" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestInsert(t *testing.T) { @@ -68,7 +68,7 @@ func TestInsert(t *testing.T) { Name: "multiline", Usage: "multiline", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--multiline=true", "bar", "baz"})) c = cli.NewContext(app, fs, nil) diff --git a/pkg/action/jsonapi.go b/pkg/action/jsonapi.go index b7a783bf52..9a858a06eb 100644 --- a/pkg/action/jsonapi.go +++ b/pkg/action/jsonapi.go @@ -12,7 +12,7 @@ import ( "github.com/fatih/color" "github.com/pkg/errors" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // JSONAPI reads a json message on stdin and responds on stdout diff --git a/pkg/action/jsonapi_others.go b/pkg/action/jsonapi_others.go index 7c43942ee3..302e2c1e3f 100644 --- a/pkg/action/jsonapi_others.go +++ b/pkg/action/jsonapi_others.go @@ -14,7 +14,7 @@ import ( "github.com/gopasspw/gopass/pkg/termio" "github.com/fatih/color" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // SetupNativeMessaging sets up manifest for gopass as native messaging host diff --git a/pkg/action/jsonapi_test.go b/pkg/action/jsonapi_test.go index e5a3de839c..a6b4832979 100644 --- a/pkg/action/jsonapi_test.go +++ b/pkg/action/jsonapi_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestJSONAPI(t *testing.T) { diff --git a/pkg/action/jsonapi_windows.go b/pkg/action/jsonapi_windows.go index d089c7a0ff..23e8d4a77a 100644 --- a/pkg/action/jsonapi_windows.go +++ b/pkg/action/jsonapi_windows.go @@ -14,7 +14,7 @@ import ( "github.com/gopasspw/gopass/pkg/termio" "github.com/fatih/color" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" "golang.org/x/sys/windows/registry" ) diff --git a/pkg/action/list.go b/pkg/action/list.go index a72a723cdd..f65d3c80cc 100644 --- a/pkg/action/list.go +++ b/pkg/action/list.go @@ -16,7 +16,7 @@ import ( "github.com/fatih/color" shellquote "github.com/kballard/go-shellquote" "github.com/pkg/errors" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // List all secrets as a tree. If the filter argument is non-empty diff --git a/pkg/action/list_test.go b/pkg/action/list_test.go index 92ed1d71e3..45e34672f8 100644 --- a/pkg/action/list_test.go +++ b/pkg/action/list_test.go @@ -15,7 +15,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestList(t *testing.T) { @@ -70,7 +70,7 @@ func TestList(t *testing.T) { Name: "flat", Usage: "flat", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--flat=true", "foo"})) c = cli.NewContext(app, fs, nil) @@ -92,7 +92,7 @@ func TestList(t *testing.T) { Name: "folders", Usage: "folders", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--folders=true"})) c = cli.NewContext(app, fs, nil) diff --git a/pkg/action/mount.go b/pkg/action/mount.go index ca1e237854..9e4f11a71a 100644 --- a/pkg/action/mount.go +++ b/pkg/action/mount.go @@ -13,16 +13,16 @@ import ( "github.com/pkg/errors" "github.com/fatih/color" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // MountRemove removes an existing mount func (s *Action) MountRemove(ctx context.Context, c *cli.Context) error { - if len(c.Args()) != 1 { + if c.Args().Len() != 1 { return ExitError(ctx, ExitUsage, nil, "Usage: %s mount remove [alias]", s.Name) } - if err := s.Store.RemoveMount(ctx, c.Args()[0]); err != nil { + if err := s.Store.RemoveMount(ctx, c.Args().Get(0)); err != nil { out.Error(ctx, "Failed to remove mount: %s", err) } @@ -30,7 +30,7 @@ func (s *Action) MountRemove(ctx context.Context, c *cli.Context) error { return ExitError(ctx, ExitConfig, err, "failed to write config: %s", err) } - out.Green(ctx, "Password Store %s umounted", c.Args()[0]) + out.Green(ctx, "Password Store %s umounted", c.Args().Get(0)) return nil } diff --git a/pkg/action/mount_test.go b/pkg/action/mount_test.go index 7d8b485f35..985478f26a 100644 --- a/pkg/action/mount_test.go +++ b/pkg/action/mount_test.go @@ -15,7 +15,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestMounts(t *testing.T) { diff --git a/pkg/action/move.go b/pkg/action/move.go index e7b4824e93..e3065eabf8 100644 --- a/pkg/action/move.go +++ b/pkg/action/move.go @@ -6,19 +6,19 @@ import ( "github.com/gopasspw/gopass/pkg/termio" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // Move the content from one secret to another func (s *Action) Move(ctx context.Context, c *cli.Context) error { force := c.Bool("force") - if len(c.Args()) != 2 { + if c.Args().Len() != 2 { return ExitError(ctx, ExitUsage, nil, "Usage: %s mv old-path new-path", s.Name) } - from := c.Args()[0] - to := c.Args()[1] + from := c.Args().Get(0) + to := c.Args().Get(1) if !force { if s.Store.Exists(ctx, to) && !termio.AskForConfirmation(ctx, fmt.Sprintf("%s already exists. Overwrite it?", to)) { diff --git a/pkg/action/move_test.go b/pkg/action/move_test.go index b556ceddd2..8092a36653 100644 --- a/pkg/action/move_test.go +++ b/pkg/action/move_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestMove(t *testing.T) { diff --git a/pkg/action/otp.go b/pkg/action/otp.go index fd4afa7df9..ffe42f3cf7 100644 --- a/pkg/action/otp.go +++ b/pkg/action/otp.go @@ -13,7 +13,7 @@ import ( "github.com/gopasspw/gopass/pkg/out" "github.com/gopasspw/gopass/pkg/store" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) const ( diff --git a/pkg/action/otp_test.go b/pkg/action/otp_test.go index 2c3721a895..b7dbfdb1b2 100644 --- a/pkg/action/otp_test.go +++ b/pkg/action/otp_test.go @@ -16,7 +16,7 @@ import ( "github.com/gokyle/twofactor" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestOTP(t *testing.T) { @@ -65,7 +65,7 @@ func TestOTP(t *testing.T) { Name: "qr", Usage: "qr", } - assert.NoError(t, sf.ApplyWithError(fs)) + assert.NoError(t, sf.Apply(fs)) fn := filepath.Join(u.Dir, "qr.png") assert.NoError(t, fs.Parse([]string{"--qr=" + fn, "bar"})) c = cli.NewContext(app, fs, nil) diff --git a/pkg/action/recipients.go b/pkg/action/recipients.go index 3aaa61a407..57abffc889 100644 --- a/pkg/action/recipients.go +++ b/pkg/action/recipients.go @@ -12,7 +12,7 @@ import ( "github.com/gopasspw/gopass/pkg/store/sub" "github.com/gopasspw/gopass/pkg/termio" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var ( @@ -75,7 +75,7 @@ func (s *Action) RecipientsAdd(ctx context.Context, c *cli.Context) error { crypto := s.Store.Crypto(ctx, store) // select recipient - recipients := []string(c.Args()) + recipients := []string(c.Args().Slice()) if len(recipients) < 1 { r, err := s.recipientsSelectForAdd(ctx, store) if err != nil { @@ -138,7 +138,7 @@ func (s *Action) RecipientsRemove(ctx context.Context, c *cli.Context) error { crypto := s.Store.Crypto(ctx, store) // select recipient - recipients := []string(c.Args()) + recipients := []string(c.Args().Slice()) if len(recipients) < 1 { rs, err := s.recipientsSelectForRemoval(ctx, store) if err != nil { diff --git a/pkg/action/recipients_test.go b/pkg/action/recipients_test.go index 47cd314f56..54376d5141 100644 --- a/pkg/action/recipients_test.go +++ b/pkg/action/recipients_test.go @@ -15,7 +15,7 @@ import ( "github.com/muesli/goprogressbar" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestRecipients(t *testing.T) { diff --git a/pkg/action/show.go b/pkg/action/show.go index e904164acd..e62d9c2496 100644 --- a/pkg/action/show.go +++ b/pkg/action/show.go @@ -14,7 +14,7 @@ import ( "github.com/gopasspw/gopass/pkg/store" "github.com/pkg/errors" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) const ( diff --git a/pkg/action/show_test.go b/pkg/action/show_test.go index 60a6658aa3..a5901a13bd 100644 --- a/pkg/action/show_test.go +++ b/pkg/action/show_test.go @@ -16,7 +16,7 @@ import ( "github.com/fatih/color" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestShow(t *testing.T) { @@ -56,7 +56,7 @@ func TestShow(t *testing.T) { Name: "sync", Usage: "sync", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--sync", "foo"})) c = cli.NewContext(app, fs, nil) @@ -101,7 +101,7 @@ func TestShow(t *testing.T) { Name: "force", Usage: "force", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--force", "foo"})) c = cli.NewContext(app, fs, nil) @@ -116,7 +116,7 @@ func TestShow(t *testing.T) { Name: "clip", Usage: "clip", } - assert.NoError(t, bf.ApplyWithError(fs)) + assert.NoError(t, bf.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--clip", "bar/baz"})) c = cli.NewContext(app, fs, nil) diff --git a/pkg/action/sync.go b/pkg/action/sync.go index 4949b8461c..179b5e38dc 100644 --- a/pkg/action/sync.go +++ b/pkg/action/sync.go @@ -11,7 +11,7 @@ import ( "github.com/fatih/color" "github.com/pkg/errors" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // Sync all stores with their remotes diff --git a/pkg/action/sync_test.go b/pkg/action/sync_test.go index 1d9a0dd27f..9106941d5d 100644 --- a/pkg/action/sync_test.go +++ b/pkg/action/sync_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestSync(t *testing.T) { @@ -47,7 +47,7 @@ func TestSync(t *testing.T) { Name: "store", Usage: "store", } - assert.NoError(t, sf.ApplyWithError(fs)) + assert.NoError(t, sf.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--store=root"})) c = cli.NewContext(app, fs, nil) diff --git a/pkg/action/templates.go b/pkg/action/templates.go index 0484b375f8..196f18ed35 100644 --- a/pkg/action/templates.go +++ b/pkg/action/templates.go @@ -10,7 +10,7 @@ import ( "github.com/gopasspw/gopass/pkg/out" "github.com/gopasspw/gopass/pkg/tpl" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) const ( diff --git a/pkg/action/templates_test.go b/pkg/action/templates_test.go index 3b7981b966..295d85e571 100644 --- a/pkg/action/templates_test.go +++ b/pkg/action/templates_test.go @@ -18,7 +18,7 @@ import ( "github.com/fatih/color" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestTemplates(t *testing.T) { diff --git a/pkg/action/unclip.go b/pkg/action/unclip.go index a747748a10..44e3d33a3c 100644 --- a/pkg/action/unclip.go +++ b/pkg/action/unclip.go @@ -7,7 +7,7 @@ import ( "github.com/gopasspw/gopass/pkg/clipboard" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // Unclip tries to erase the content of the clipboard diff --git a/pkg/action/unclip_test.go b/pkg/action/unclip_test.go index d9eaba09f4..3c547c9700 100644 --- a/pkg/action/unclip_test.go +++ b/pkg/action/unclip_test.go @@ -11,7 +11,7 @@ import ( "github.com/gopasspw/gopass/tests/gptest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" _ "github.com/gopasspw/gopass/pkg/backend/crypto" _ "github.com/gopasspw/gopass/pkg/backend/rcs" @@ -42,7 +42,7 @@ func TestUnclip(t *testing.T) { Name: "timeout", Usage: "timeout", } - assert.NoError(t, sf.ApplyWithError(fs)) + assert.NoError(t, sf.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--timeout=0"})) c := cli.NewContext(app, fs, nil) diff --git a/pkg/action/update.go b/pkg/action/update.go index e12e51fb9e..66299fc0e0 100644 --- a/pkg/action/update.go +++ b/pkg/action/update.go @@ -6,7 +6,7 @@ import ( "github.com/gopasspw/gopass/pkg/out" "github.com/gopasspw/gopass/pkg/updater" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // Update will start the interactive update assistant diff --git a/pkg/action/update_test.go b/pkg/action/update_test.go index 3988bfa671..fe99db2212 100644 --- a/pkg/action/update_test.go +++ b/pkg/action/update_test.go @@ -25,7 +25,7 @@ import ( "github.com/dominikschulz/github-releases/ghrel" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) const testUpdateJSON = `[ diff --git a/pkg/action/version.go b/pkg/action/version.go index 19e1111541..44fa9a8936 100644 --- a/pkg/action/version.go +++ b/pkg/action/version.go @@ -14,7 +14,7 @@ import ( "github.com/gopasspw/gopass/pkg/updater" "github.com/fatih/color" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // Version prints the gopass version diff --git a/pkg/action/version_test.go b/pkg/action/version_test.go index ad629c4bfc..9c831fc54e 100644 --- a/pkg/action/version_test.go +++ b/pkg/action/version_test.go @@ -17,7 +17,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestVersion(t *testing.T) { diff --git a/pkg/action/xc/no_xc.go b/pkg/action/xc/no_xc.go index 483029acc2..bb4864f853 100644 --- a/pkg/action/xc/no_xc.go +++ b/pkg/action/xc/no_xc.go @@ -5,7 +5,7 @@ package xc import ( "context" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // ListPrivateKeys list the XC private keys diff --git a/pkg/action/xc/xc.go b/pkg/action/xc/xc.go index ef7453cda0..3c8a97c09d 100644 --- a/pkg/action/xc/xc.go +++ b/pkg/action/xc/xc.go @@ -15,7 +15,7 @@ import ( "github.com/gopasspw/gopass/pkg/fsutil" "github.com/gopasspw/gopass/pkg/out" "github.com/gopasspw/gopass/pkg/termio" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var crypto *xc.XC diff --git a/pkg/action/xc/xc_test.go b/pkg/action/xc/xc_test.go index ecec390a13..7a522313a2 100644 --- a/pkg/action/xc/xc_test.go +++ b/pkg/action/xc/xc_test.go @@ -16,7 +16,7 @@ import ( "github.com/gopasspw/gopass/pkg/ctxutil" "github.com/gopasspw/gopass/pkg/out" "github.com/stretchr/testify/assert" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestListPrivateKeys(t *testing.T) { @@ -67,17 +67,17 @@ func TestGenerateKeypair(t *testing.T) { Name: "name", Usage: "name", } - assert.NoError(t, nf.ApplyWithError(fs)) + assert.NoError(t, nf.Apply(fs)) ef := cli.StringFlag{ Name: "email", Usage: "email", } - assert.NoError(t, ef.ApplyWithError(fs)) + assert.NoError(t, ef.Apply(fs)) pf := cli.StringFlag{ Name: "passphrase", Usage: "passphrase", } - assert.NoError(t, pf.ApplyWithError(fs)) + assert.NoError(t, pf.Apply(fs)) c := cli.NewContext(app, fs, nil) assert.Error(t, GenerateKeypair(ctx, c)) @@ -105,12 +105,12 @@ func TestExportPublicKey(t *testing.T) { Name: "id", Usage: "id", } - assert.NoError(t, id.ApplyWithError(fs)) + assert.NoError(t, id.Apply(fs)) ff := cli.StringFlag{ Name: "file", Usage: "file", } - assert.NoError(t, ff.ApplyWithError(fs)) + assert.NoError(t, ff.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--id=foo", "--file=/tmp/foo.pub"})) c := cli.NewContext(app, fs, nil) @@ -133,7 +133,7 @@ func TestImportPublicKey(t *testing.T) { Name: "file", Usage: "file", } - assert.NoError(t, ff.ApplyWithError(fs)) + assert.NoError(t, ff.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--file=/tmp/foo.pub"})) c := cli.NewContext(app, fs, nil) @@ -156,12 +156,12 @@ func TestExportPrivateKey(t *testing.T) { Name: "id", Usage: "id", } - assert.NoError(t, id.ApplyWithError(fs)) + assert.NoError(t, id.Apply(fs)) ff := cli.StringFlag{ Name: "file", Usage: "file", } - assert.NoError(t, ff.ApplyWithError(fs)) + assert.NoError(t, ff.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--id=foo", "--file=/tmp/foo.pub"})) c := cli.NewContext(app, fs, nil) @@ -184,7 +184,7 @@ func TestImportPrivateKey(t *testing.T) { Name: "file", Usage: "file", } - assert.NoError(t, ff.ApplyWithError(fs)) + assert.NoError(t, ff.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--file=/tmp/foo.pub"})) c := cli.NewContext(app, fs, nil) @@ -228,7 +228,7 @@ func TestEncryptDecryptFile(t *testing.T) { Name: "file", Usage: "file", } - assert.NoError(t, ff.ApplyWithError(fs)) + assert.NoError(t, ff.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--file=" + plain})) c := cli.NewContext(app, fs, nil) assert.NoError(t, EncryptFile(ctx, c)) @@ -275,7 +275,7 @@ func TestEncryptDecryptStream(t *testing.T) { Name: "file", Usage: "file", } - assert.NoError(t, ff.ApplyWithError(fs)) + assert.NoError(t, ff.Apply(fs)) assert.NoError(t, fs.Parse([]string{"--file=" + plain})) c := cli.NewContext(app, fs, nil) assert.NoError(t, EncryptFileStream(ctx, c)) diff --git a/pkg/completion/fish/completion.go b/pkg/completion/fish/completion.go deleted file mode 100644 index 9a5203f64d..0000000000 --- a/pkg/completion/fish/completion.go +++ /dev/null @@ -1,88 +0,0 @@ -package fish - -import ( - "bytes" - "fmt" - "html/template" - "strings" - - "github.com/urfave/cli" -) - -func longName(name string) string { - // "If s does not contain sep and sep is not empty, Split returns a slice of length 1 whose only element is s." - // from https://golang.org/pkg/strings/#Split - return strings.TrimSpace(strings.Split(name, ",")[0]) -} - -func shortName(name string) string { - parts := strings.Split(name, ",") - if len(parts) < 2 { - return "" - } - return strings.TrimSpace(parts[1]) -} - -func formatFlag(name, usage, typ string) string { - switch typ { - case "short": - return shortName(name) - case "long": - return longName(name) - case "usage": - return usage - default: - return "" - } -} - -func formatFlagFunc(typ string) func(cli.Flag) (string, error) { - return func(f cli.Flag) (string, error) { - switch ft := f.(type) { - case cli.BoolFlag: - return formatFlag(ft.Name, ft.Usage, typ), nil - case cli.BoolTFlag: - return formatFlag(ft.Name, ft.Usage, typ), nil - case cli.Float64Flag: - return formatFlag(ft.Name, ft.Usage, typ), nil - case cli.GenericFlag: - return formatFlag(ft.Name, ft.Usage, typ), nil - case cli.Int64Flag: - return formatFlag(ft.Name, ft.Usage, typ), nil - case cli.Int64SliceFlag: - return formatFlag(ft.Name, ft.Usage, typ), nil - case cli.IntFlag: - return formatFlag(ft.Name, ft.Usage, typ), nil - case cli.IntSliceFlag: - return formatFlag(ft.Name, ft.Usage, typ), nil - case cli.StringFlag: - return formatFlag(ft.Name, ft.Usage, typ), nil - case cli.StringSliceFlag: - return formatFlag(ft.Name, ft.Usage, typ), nil - case cli.Uint64Flag: - return formatFlag(ft.Name, ft.Usage, typ), nil - case cli.UintFlag: - return formatFlag(ft.Name, ft.Usage, typ), nil - default: - return "", fmt.Errorf("unknown type: '%T'", f) - } - } -} - -// GetCompletion returns a fish completion script -func GetCompletion(a *cli.App) (string, error) { - tplFuncs := template.FuncMap{ - "formatShortFlag": formatFlagFunc("short"), - "formatLongFlag": formatFlagFunc("long"), - "formatFlagUsage": formatFlagFunc("usage"), - } - tpl, err := template.New("fish").Funcs(tplFuncs).Parse(fishTemplate) - if err != nil { - return "", err - } - buf := &bytes.Buffer{} - if err := tpl.Execute(buf, a); err != nil { - return "", err - } - return buf.String(), nil -} diff --git a/pkg/completion/fish/completion_test.go b/pkg/completion/fish/completion_test.go deleted file mode 100644 index 9b47f021da..0000000000 --- a/pkg/completion/fish/completion_test.go +++ /dev/null @@ -1,96 +0,0 @@ -package fish - -import ( - "flag" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "github.com/urfave/cli" -) - -type unknownFlag struct{} - -func (u unknownFlag) String() string { - return "" -} - -func (u unknownFlag) Apply(*flag.FlagSet) {} -func (u unknownFlag) GetName() string { - return "" -} - -func TestFormatFlag(t *testing.T) { - for _, tc := range []struct { - Name string - Usage string - Typ string - Out string - }{ - {"print, p", "Print", "short", "p"}, - {"print, p", "Print", "long", "print"}, - {"print, p", "Print", "usage", "Print"}, - {"print", "Print", "short", ""}, - {"", "Print", "long", ""}, - {"print, p", "Print", "foo", ""}, - } { - assert.Equal(t, tc.Out, formatFlag(tc.Name, tc.Usage, tc.Typ)) - } -} - -func TestGetCompletion(t *testing.T) { - app := cli.NewApp() - sv, err := GetCompletion(app) - require.NoError(t, err) - assert.Contains(t, sv, "#!/usr/bin/env fish") - - fishTemplate = "{{.unexported}}" - sv, err = GetCompletion(app) - assert.Error(t, err) - assert.Contains(t, sv, "") - - fishTemplate = "{{}}" - sv, err = GetCompletion(app) - assert.Error(t, err) - assert.Contains(t, sv, "") -} - -func TestFormatflagFunc(t *testing.T) { - for _, flag := range []cli.Flag{ - cli.BoolFlag{Name: "foo", Usage: "bar"}, - cli.Float64Flag{Name: "foo", Usage: "bar"}, - cli.GenericFlag{Name: "foo", Usage: "bar"}, - cli.Int64Flag{Name: "foo", Usage: "bar"}, - cli.Int64SliceFlag{Name: "foo", Usage: "bar"}, - cli.IntFlag{Name: "foo", Usage: "bar"}, - cli.IntSliceFlag{Name: "foo", Usage: "bar"}, - cli.StringFlag{Name: "foo", Usage: "bar"}, - cli.StringSliceFlag{Name: "foo", Usage: "bar"}, - cli.Uint64Flag{Name: "foo", Usage: "bar"}, - cli.UintFlag{Name: "foo", Usage: "bar"}, - } { - sv, err := formatFlagFunc("short")(flag) - require.NoError(t, err) - assert.Equal(t, "", sv) - - sv, err = formatFlagFunc("long")(flag) - require.NoError(t, err) - assert.Equal(t, "foo", sv) - - sv, err = formatFlagFunc("usage")(flag) - require.NoError(t, err) - assert.Equal(t, "bar", sv) - } - - sv, err := formatFlagFunc("short")(unknownFlag{}) - assert.Error(t, err) - assert.Equal(t, "", sv) - - sv, err = formatFlagFunc("long")(unknownFlag{}) - assert.Error(t, err) - assert.Equal(t, "", sv) - - sv, err = formatFlagFunc("usage")(unknownFlag{}) - assert.Error(t, err) - assert.Equal(t, "", sv) -} diff --git a/pkg/completion/fish/template.go b/pkg/completion/fish/template.go deleted file mode 100644 index 23edd99ccb..0000000000 --- a/pkg/completion/fish/template.go +++ /dev/null @@ -1,62 +0,0 @@ -package fish - -// see https://fishshell.com/docs/current/commands.html#complete -var fishTemplate = `#!/usr/bin/env fish -{{ $prog := .Name -}} -set PROG '{{ $prog }}' - -function __fish_{{ $prog }}_needs_command - set -l cmd (commandline -opc) - if [ (count $cmd) -eq 1 -a $cmd[1] = $PROG ] - return 0 - end - return 1 -end - -function __fish_{{ $prog }}_uses_command - set cmd (commandline -opc) - if [ (count $cmd) -gt 1 ] - if [ $argv[1] = $cmd[2] ] - return 0 - end - end - return 1 -end - -function __fish_{{ $prog }}_print_gpg_keys - gpg2 --list-keys | grep uid | sed 's/.*<\(.*\)>/\1/' -end - -function __fish_{{ $prog }}_print_entries - {{ $prog }} ls --flat -end - -function __fish_{{ $prog }}_print_dir - for i in ({{ $prog }} ls --flat) - echo (dirname $i) - end | sort -u -end - -# erase any existing completions for {{ $prog }} -complete -c $PROG -e -complete -c $PROG -f -n '__fish_{{ $prog }}_needs_command' -a "(__fish_{{ $prog }}_print_entries)" -complete -c $PROG -f -s c -l clip -r -a "(__fish_{{ $prog }}_print_entries)" -{{- $gflags := .Flags -}} -{{ range .Commands }} -complete -c $PROG -f -n '__fish_{{ $prog }}_needs_command' -a {{ .Name }} -d 'Command: {{ .Usage }}' -{{- $cmd := .Name -}} -{{- if or (eq $cmd "copy") (eq $cmd "cp") (eq $cmd "move") (eq $cmd "mv") (eq $cmd "delete") (eq $cmd "remove") (eq $cmd "rm") (eq $cmd "show") (eq $cmd "set") (eq $cmd "edit") }} -complete -c $PROG -f -n '__fish_{{ $prog }}_uses_command {{ $cmd }}' -a "(__fish_{{ $prog }}_print_entries)"{{ end -}} -{{- if or (eq $cmd "insert") (eq $cmd "generate") (eq $cmd "list") (eq $cmd "ls") }} -complete -c $PROG -f -n '__fish_{{ $prog }}_uses_command {{ $cmd }}' -a "(__fish_{{ $prog }}_print_dir)"{{ end -}} -{{- range .Subcommands }} -{{- $subcmd := .Name }} -complete -c $PROG -f -n '__fish_{{ $prog }}_uses_command {{ $cmd }}' -a {{ $subcmd }} -d 'Subcommand: {{ .Usage }}' -{{- range .Flags }} -complete -c $PROG -f -n '__fish_{{ $prog }}_uses_command {{ $cmd }} {{ $subcmd }} {{ if ne (. | formatShortFlag) "" }}-s {{ . | formatShortFlag }} {{ end }}-l {{ . | formatLongFlag }} -d "{{ . | formatFlagUsage }}"' -{{- end }} -{{- range $gflags }} -complete -c $PROG -f -n '__fish_{{ $prog }}_uses_command {{ $cmd }} {{ $subcmd }} {{ if ne (. | formatShortFlag) "" }}-s {{ . | formatShortFlag }} {{ end }}-l {{ . | formatLongFlag }} -d "{{ . | formatFlagUsage }}"' -{{- end }} -{{- end }} -{{- end }}` diff --git a/pkg/completion/zsh/completion.go b/pkg/completion/zsh/completion.go index 2a267ed5ea..93e8e4f946 100644 --- a/pkg/completion/zsh/completion.go +++ b/pkg/completion/zsh/completion.go @@ -6,7 +6,7 @@ import ( "strings" "text/template" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func longName(name string) string { @@ -22,29 +22,27 @@ func formatFlag(name, usage string) string { func formatFlagFunc() func(cli.Flag) (string, error) { return func(f cli.Flag) (string, error) { switch ft := f.(type) { - case cli.BoolFlag: + case *cli.BoolFlag: return formatFlag(ft.Name, ft.Usage), nil - case cli.BoolTFlag: + case *cli.Float64Flag: return formatFlag(ft.Name, ft.Usage), nil - case cli.Float64Flag: + case *cli.GenericFlag: return formatFlag(ft.Name, ft.Usage), nil - case cli.GenericFlag: + case *cli.Int64Flag: return formatFlag(ft.Name, ft.Usage), nil - case cli.Int64Flag: + case *cli.Int64SliceFlag: return formatFlag(ft.Name, ft.Usage), nil - case cli.Int64SliceFlag: + case *cli.IntFlag: return formatFlag(ft.Name, ft.Usage), nil - case cli.IntFlag: + case *cli.IntSliceFlag: return formatFlag(ft.Name, ft.Usage), nil - case cli.IntSliceFlag: + case *cli.StringFlag: return formatFlag(ft.Name, ft.Usage), nil - case cli.StringFlag: + case *cli.StringSliceFlag: return formatFlag(ft.Name, ft.Usage), nil - case cli.StringSliceFlag: + case *cli.Uint64Flag: return formatFlag(ft.Name, ft.Usage), nil - case cli.Uint64Flag: - return formatFlag(ft.Name, ft.Usage), nil - case cli.UintFlag: + case *cli.UintFlag: return formatFlag(ft.Name, ft.Usage), nil default: return "", fmt.Errorf("unknown type: '%T'", f) diff --git a/pkg/completion/zsh/completion_test.go b/pkg/completion/zsh/completion_test.go index 0df83c61fe..74da09c5c7 100644 --- a/pkg/completion/zsh/completion_test.go +++ b/pkg/completion/zsh/completion_test.go @@ -6,19 +6,27 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) type unknownFlag struct{} -func (u unknownFlag) String() string { +func (u *unknownFlag) String() string { return "" } -func (u unknownFlag) Apply(*flag.FlagSet) {} -func (u unknownFlag) GetName() string { +func (u *unknownFlag) Apply(*flag.FlagSet) error { + return nil +} +func (u *unknownFlag) GetName() string { return "" } +func (u *unknownFlag) IsSet() bool { + return true +} +func (u *unknownFlag) Names() []string { + return []string{} +} func TestFormatFlag(t *testing.T) { for _, tc := range []struct { @@ -52,23 +60,23 @@ func TestGetCompletion(t *testing.T) { func TestFormatflagFunc(t *testing.T) { ff := formatFlagFunc() for _, flag := range []cli.Flag{ - cli.BoolFlag{Name: "foo", Usage: "bar"}, - cli.Float64Flag{Name: "foo", Usage: "bar"}, - cli.GenericFlag{Name: "foo", Usage: "bar"}, - cli.Int64Flag{Name: "foo", Usage: "bar"}, - cli.Int64SliceFlag{Name: "foo", Usage: "bar"}, - cli.IntFlag{Name: "foo", Usage: "bar"}, - cli.IntSliceFlag{Name: "foo", Usage: "bar"}, - cli.StringFlag{Name: "foo", Usage: "bar"}, - cli.StringSliceFlag{Name: "foo", Usage: "bar"}, - cli.Uint64Flag{Name: "foo", Usage: "bar"}, - cli.UintFlag{Name: "foo", Usage: "bar"}, + &cli.BoolFlag{Name: "foo", Usage: "bar"}, + &cli.Float64Flag{Name: "foo", Usage: "bar"}, + &cli.GenericFlag{Name: "foo", Usage: "bar"}, + &cli.Int64Flag{Name: "foo", Usage: "bar"}, + &cli.Int64SliceFlag{Name: "foo", Usage: "bar"}, + &cli.IntFlag{Name: "foo", Usage: "bar"}, + &cli.IntSliceFlag{Name: "foo", Usage: "bar"}, + &cli.StringFlag{Name: "foo", Usage: "bar"}, + &cli.StringSliceFlag{Name: "foo", Usage: "bar"}, + &cli.Uint64Flag{Name: "foo", Usage: "bar"}, + &cli.UintFlag{Name: "foo", Usage: "bar"}, } { sv, err := ff(flag) require.NoError(t, err) assert.Equal(t, "--foo[bar]", sv) } - sv, err := ff(unknownFlag{}) + sv, err := ff(&unknownFlag{}) assert.Error(t, err) assert.Equal(t, "", sv) } diff --git a/pkg/cui/actions.go b/pkg/cui/actions.go index 35711ce5cc..55aaaa059d 100644 --- a/pkg/cui/actions.go +++ b/pkg/cui/actions.go @@ -4,7 +4,7 @@ import ( "context" "errors" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // Action is a action which can be selected diff --git a/pkg/cui/actions_test.go b/pkg/cui/actions_test.go index 763f5f0b3d..ae722c8f62 100644 --- a/pkg/cui/actions_test.go +++ b/pkg/cui/actions_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestCreateActions(t *testing.T) { diff --git a/pkg/editor/edit_linux.go b/pkg/editor/edit_linux.go index 2e1783073c..03c218f3f5 100644 --- a/pkg/editor/edit_linux.go +++ b/pkg/editor/edit_linux.go @@ -6,7 +6,7 @@ import ( "os" "os/exec" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // Path return the name/path of the preferred editor diff --git a/pkg/editor/edit_others.go b/pkg/editor/edit_others.go index 939cbc50f2..e70e5fff1a 100644 --- a/pkg/editor/edit_others.go +++ b/pkg/editor/edit_others.go @@ -5,7 +5,7 @@ package editor import ( "os" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // Path return the name/path of the preferred editor diff --git a/pkg/editor/edit_test.go b/pkg/editor/edit_test.go index f39988ca28..0049ab2c29 100644 --- a/pkg/editor/edit_test.go +++ b/pkg/editor/edit_test.go @@ -15,7 +15,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func TestEdit(t *testing.T) { @@ -62,7 +62,7 @@ func TestGetEditor(t *testing.T) { Name: "editor", Usage: "editor", } - require.NoError(t, sf.ApplyWithError(fs)) + require.NoError(t, sf.Apply(fs)) require.NoError(t, fs.Parse([]string{"--editor", "fooed"})) c := cli.NewContext(app, fs, nil) diff --git a/pkg/editor/edit_windows.go b/pkg/editor/edit_windows.go index dee912fa11..a042621740 100644 --- a/pkg/editor/edit_windows.go +++ b/pkg/editor/edit_windows.go @@ -5,7 +5,7 @@ package editor import ( "os" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // Path return the name/path of the preferred editor