github.com/iotexproject/iotex-core@v1.14.1-rc1/ioctl/newcmd/hdwallet/hdwalletdelete.go (about)

     1  // Copyright (c) 2022 IoTeX Foundation
     2  // This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability
     3  // or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed.
     4  // This source code is governed by Apache License 2.0 that can be found in the LICENSE file.
     5  
     6  package hdwallet
     7  
     8  import (
     9  	"fmt"
    10  
    11  	"github.com/pkg/errors"
    12  	"github.com/spf13/cobra"
    13  
    14  	"github.com/iotexproject/iotex-core/ioctl"
    15  	"github.com/iotexproject/iotex-core/ioctl/config"
    16  )
    17  
    18  // Multi-language support
    19  var (
    20  	_hdwalletDeleteCmdShorts = map[config.Language]string{
    21  		config.English: "delete hdwallet",
    22  		config.Chinese: "删除钱包",
    23  	}
    24  )
    25  
    26  // NewHdwalletDeleteCmd represents the hdwallet delete command
    27  func NewHdwalletDeleteCmd(client ioctl.Client) *cobra.Command {
    28  	short, _ := client.SelectTranslation(_hdwalletDeleteCmdShorts)
    29  
    30  	return &cobra.Command{
    31  		Use:   "delete",
    32  		Short: short,
    33  		Args:  cobra.ExactArgs(0),
    34  		RunE: func(cmd *cobra.Command, args []string) error {
    35  			cmd.SilenceUsage = true
    36  			info := fmt.Sprintf("** This is an irreversible action!\n" +
    37  				"Once an hdwallet is deleted, all the assets under this hdwallet may be lost!\n" +
    38  				"Type 'YES' to continue, quit for anything else.")
    39  			confirmed, err := client.AskToConfirm(info)
    40  			if err != nil {
    41  				return errors.Wrap(err, "failed to ask confirm")
    42  			}
    43  			if !confirmed {
    44  				cmd.Println("quit")
    45  				return nil
    46  			}
    47  
    48  			return client.RemoveHdWalletConfigFile()
    49  		},
    50  	}
    51  }