github.com/iotexproject/iotex-core@v1.14.1-rc1/ioctl/newcmd/config/config_reset.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 config
     7  
     8  import (
     9  	"github.com/pkg/errors"
    10  	"github.com/spf13/cobra"
    11  
    12  	"github.com/iotexproject/iotex-core/ioctl"
    13  	"github.com/iotexproject/iotex-core/ioctl/config"
    14  )
    15  
    16  var (
    17  	_configResetCmdShorts = map[config.Language]string{
    18  		config.English: "Reset config to default",
    19  		config.Chinese: "将配置重置为默认值",
    20  	}
    21  )
    22  
    23  // NewConfigResetCmd resets the config to the default values
    24  func NewConfigResetCmd(client ioctl.Client) *cobra.Command {
    25  	short, _ := client.SelectTranslation(_configResetCmdShorts)
    26  
    27  	return &cobra.Command{
    28  		Use:   "reset",
    29  		Short: short,
    30  		RunE: func(cmd *cobra.Command, args []string) error {
    31  			cmd.SilenceUsage = true
    32  			err := newInfo(client.Config(), client.ConfigFilePath()).reset()
    33  			if err != nil {
    34  				return errors.Wrap(err, "failed to reset config")
    35  			}
    36  			cmd.Println("successfully reset config")
    37  			return nil
    38  		},
    39  	}
    40  }