github.com/iotexproject/iotex-core@v1.14.1-rc1/ioctl/cmd/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  	"os"
    11  	"strings"
    12  
    13  	"github.com/spf13/cobra"
    14  
    15  	"github.com/iotexproject/iotex-core/ioctl/config"
    16  	"github.com/iotexproject/iotex-core/ioctl/output"
    17  )
    18  
    19  // Multi-language support
    20  var (
    21  	_hdwalletDeleteCmdShorts = map[config.Language]string{
    22  		config.English: "delete hdwallet",
    23  		config.Chinese: "删除钱包",
    24  	}
    25  )
    26  
    27  // _hdwalletDeleteCmd represents the hdwallet delete command
    28  var _hdwalletDeleteCmd = &cobra.Command{
    29  	Use:   "delete",
    30  	Short: config.TranslateInLang(_hdwalletDeleteCmdShorts, config.UILanguage),
    31  	Args:  cobra.ExactArgs(0),
    32  	RunE: func(cmd *cobra.Command, args []string) error {
    33  		cmd.SilenceUsage = true
    34  		err := hdwalletDelete()
    35  		return output.PrintError(err)
    36  	},
    37  }
    38  
    39  func hdwalletDelete() error {
    40  	var confirm string
    41  	info := fmt.Sprintf("** This is an irreversible action!\n" +
    42  		"Once an hdwallet is deleted, all the assets under this hdwallet may be lost!\n" +
    43  		"Type 'YES' to continue, quit for anything else.")
    44  	message := output.ConfirmationMessage{Info: info, Options: []string{"yes"}}
    45  	fmt.Println(message.String())
    46  	if _, err := fmt.Scanf("%s", &confirm); err != nil {
    47  		return output.NewError(output.InputError, "failed to input yes", err)
    48  	}
    49  	if !strings.EqualFold(confirm, "yes") {
    50  		output.PrintResult("quit")
    51  		return nil
    52  	}
    53  
    54  	return os.Remove(_hdWalletConfigFile)
    55  }