github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/wsctl/cmd/config/reset.go (about)

     1  package config
     2  
     3  import (
     4  	"github.com/pkg/errors"
     5  	"github.com/spf13/cobra"
     6  
     7  	"github.com/machinefi/w3bstream/pkg/wsctl/client"
     8  	"github.com/machinefi/w3bstream/pkg/wsctl/config"
     9  )
    10  
    11  var (
    12  	_configResetCmdShorts = map[config.Language]string{
    13  		config.English: "Reset config to default",
    14  		config.Chinese: "将配置重置为默认值",
    15  	}
    16  )
    17  
    18  // newConfigResetCmd resets the config to the default values
    19  func newConfigResetCmd(client client.Client) *cobra.Command {
    20  	return &cobra.Command{
    21  		Use:   "reset",
    22  		Short: client.SelectTranslation(_configResetCmdShorts),
    23  		RunE: func(cmd *cobra.Command, args []string) error {
    24  			cmd.SilenceUsage = true
    25  			info := info{config: client.Config(), configFile: client.ConfigFilePath()}
    26  			err := info.reset()
    27  			if err != nil {
    28  				return errors.Wrap(err, "failed to reset config")
    29  			}
    30  			cmd.Println("successfully reset config")
    31  			return nil
    32  		},
    33  	}
    34  }