cli: use AddressFlag for 'wallet remove' command
This commit is contained in:
parent
42bfd413e3
commit
6af2f3fdec
2 changed files with 11 additions and 8 deletions
|
@ -206,11 +206,15 @@ func NewCommands() []cli.Command {
|
||||||
{
|
{
|
||||||
Name: "remove",
|
Name: "remove",
|
||||||
Usage: "remove an account from the wallet",
|
Usage: "remove an account from the wallet",
|
||||||
UsageText: "remove --wallet <path> [--force] <addr>",
|
UsageText: "remove --wallet <path> [--force] --address <addr>",
|
||||||
Action: removeAccount,
|
Action: removeAccount,
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
walletPathFlag,
|
walletPathFlag,
|
||||||
forceFlag,
|
forceFlag,
|
||||||
|
flags.AddressFlag{
|
||||||
|
Name: "address, a",
|
||||||
|
Usage: "Account address or hash in LE form to be removed",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -502,18 +506,17 @@ func removeAccount(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
defer wall.Close()
|
defer wall.Close()
|
||||||
|
|
||||||
addrArg := ctx.Args().First()
|
addr := ctx.Generic("address").(*flags.Address)
|
||||||
addr, err := address.StringToUint160(addrArg)
|
if !addr.IsSet {
|
||||||
if err != nil {
|
cli.NewExitError("valid account address must be provided", 1)
|
||||||
return cli.NewExitError("valid address must be provided", 1)
|
|
||||||
}
|
}
|
||||||
acc := wall.GetAccount(addr)
|
acc := wall.GetAccount(addr.Uint160())
|
||||||
if acc == nil {
|
if acc == nil {
|
||||||
return cli.NewExitError("account wasn't found", 1)
|
return cli.NewExitError("account wasn't found", 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.Bool("force") {
|
if !ctx.Bool("force") {
|
||||||
fmt.Fprintf(ctx.App.Writer, "Account %s will be removed. This action is irreversible.\n", addrArg)
|
fmt.Fprintf(ctx.App.Writer, "Account %s will be removed. This action is irreversible.\n", addr.Uint160())
|
||||||
if ok := askForConsent(ctx.App.Writer); !ok {
|
if ok := askForConsent(ctx.App.Writer); !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ func TestWalletInit(t *testing.T) {
|
||||||
addr := w.Accounts[0].Address
|
addr := w.Accounts[0].Address
|
||||||
e.In.WriteString("y\r")
|
e.In.WriteString("y\r")
|
||||||
e.Run(t, "neo-go", "wallet", "remove",
|
e.Run(t, "neo-go", "wallet", "remove",
|
||||||
"--wallet", walletPath, addr)
|
"--wallet", walletPath, "--address", addr)
|
||||||
w, err := wallet.NewWalletFromFile(walletPath)
|
w, err := wallet.NewWalletFromFile(walletPath)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Nil(t, w.GetAccount(sh))
|
require.Nil(t, w.GetAccount(sh))
|
||||||
|
|
Loading…
Reference in a new issue