cmd: migrate to urfave/cli/v2 (#24751)

This change updates our urfave/cli dependency to the v2 branch of the library.
There are some Go API changes in cli v2:

- Flag values can now be accessed using the methods ctx.Bool,
  ctx.Int, ctx.String, ... regardless of whether the flag is 'local' or
  'global'.

- v2 has built-in support for flag categories. Our home-grown category
  system is removed and the categories of flags are assigned as part of
  the flag definition.

For users, there is only one observable difference with cli v2: flags must now
strictly appear before regular arguments. For example, the following command is
now invalid:

   geth account import mykey.json --password file.txt

Instead, the command must be invoked as follows:

   geth account import --password file.txt mykey.json
This commit is contained in:
willian.eth
2022-06-27 18:22:36 +02:00
committed by GitHub
parent 119f955686
commit 52ed3570c4
61 changed files with 2353 additions and 2320 deletions
+3 -3
View File
@@ -23,15 +23,15 @@ import (
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/cmd/utils"
"gopkg.in/urfave/cli.v1"
"github.com/urfave/cli/v2"
)
var newPassphraseFlag = cli.StringFlag{
var newPassphraseFlag = &cli.StringFlag{
Name: "newpasswordfile",
Usage: "the file that contains the new password for the keyfile",
}
var commandChangePassphrase = cli.Command{
var commandChangePassphrase = &cli.Command{
Name: "changepassword",
Usage: "change the password on a keyfile",
ArgsUsage: "<keyfile>",
+4 -4
View File
@@ -26,7 +26,7 @@ import (
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/crypto"
"github.com/google/uuid"
"gopkg.in/urfave/cli.v1"
"github.com/urfave/cli/v2"
)
type outputGenerate struct {
@@ -35,17 +35,17 @@ type outputGenerate struct {
}
var (
privateKeyFlag = cli.StringFlag{
privateKeyFlag = &cli.StringFlag{
Name: "privatekey",
Usage: "file containing a raw private key to encrypt",
}
lightKDFFlag = cli.BoolFlag{
lightKDFFlag = &cli.BoolFlag{
Name: "lightkdf",
Usage: "use less secure scrypt parameters",
}
)
var commandGenerate = cli.Command{
var commandGenerate = &cli.Command{
Name: "generate",
Usage: "generate new keyfile",
ArgsUsage: "[ <keyfile> ]",
+3 -3
View File
@@ -24,7 +24,7 @@ import (
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/crypto"
"gopkg.in/urfave/cli.v1"
"github.com/urfave/cli/v2"
)
type outputInspect struct {
@@ -34,13 +34,13 @@ type outputInspect struct {
}
var (
privateFlag = cli.BoolFlag{
privateFlag = &cli.BoolFlag{
Name: "private",
Usage: "include the private key in the output",
}
)
var commandInspect = cli.Command{
var commandInspect = &cli.Command{
Name: "inspect",
Usage: "inspect a keyfile",
ArgsUsage: "<keyfile>",
+4 -5
View File
@@ -21,7 +21,7 @@ import (
"os"
"github.com/ethereum/go-ethereum/internal/flags"
"gopkg.in/urfave/cli.v1"
"github.com/urfave/cli/v2"
)
const (
@@ -36,23 +36,22 @@ var app *cli.App
func init() {
app = flags.NewApp(gitCommit, gitDate, "an Ethereum key manager")
app.Commands = []cli.Command{
app.Commands = []*cli.Command{
commandGenerate,
commandInspect,
commandChangePassphrase,
commandSignMessage,
commandVerifyMessage,
}
cli.CommandHelpTemplate = flags.OriginCommandHelpTemplate
}
// Commonly used command line flags.
var (
passphraseFlag = cli.StringFlag{
passphraseFlag = &cli.StringFlag{
Name: "passwordfile",
Usage: "the file that contains the password for the keyfile",
}
jsonFlag = cli.BoolFlag{
jsonFlag = &cli.BoolFlag{
Name: "json",
Usage: "output JSON instead of human-readable format",
}
+7 -7
View File
@@ -26,19 +26,19 @@ import (
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"gopkg.in/urfave/cli.v1"
"github.com/urfave/cli/v2"
)
type outputSign struct {
Signature string
}
var msgfileFlag = cli.StringFlag{
var msgfileFlag = &cli.StringFlag{
Name: "msgfile",
Usage: "file containing the message to sign/verify",
}
var commandSignMessage = cli.Command{
var commandSignMessage = &cli.Command{
Name: "signmessage",
Usage: "sign a message",
ArgsUsage: "<keyfile> <message>",
@@ -89,7 +89,7 @@ type outputVerify struct {
RecoveredPublicKey string
}
var commandVerifyMessage = cli.Command{
var commandVerifyMessage = &cli.Command{
Name: "verifymessage",
Usage: "verify the signature of a signed message",
ArgsUsage: "<address> <signature> <message>",
@@ -144,7 +144,7 @@ It is possible to refer to a file containing the message.`,
func getMessage(ctx *cli.Context, msgarg int) []byte {
if file := ctx.String(msgfileFlag.Name); file != "" {
if len(ctx.Args()) > msgarg {
if ctx.NArg() > msgarg {
utils.Fatalf("Can't use --msgfile and message argument at the same time.")
}
msg, err := os.ReadFile(file)
@@ -152,9 +152,9 @@ func getMessage(ctx *cli.Context, msgarg int) []byte {
utils.Fatalf("Can't read message file: %v", err)
}
return msg
} else if len(ctx.Args()) == msgarg+1 {
} else if ctx.NArg() == msgarg+1 {
return []byte(ctx.Args().Get(msgarg))
}
utils.Fatalf("Invalid number of arguments: want %d, got %d", msgarg+1, len(ctx.Args()))
utils.Fatalf("Invalid number of arguments: want %d, got %d", msgarg+1, ctx.NArg())
return nil
}
+1 -1
View File
@@ -23,7 +23,7 @@ import (
"strings"
"github.com/ethereum/go-ethereum/cmd/utils"
"gopkg.in/urfave/cli.v1"
"github.com/urfave/cli/v2"
)
// getPassphrase obtains a passphrase given by the user. It first checks the