2020-08-10 01:42:04 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2021-09-30 07:14:27 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
2021-09-30 06:17:58 +00:00
|
|
|
"github.com/cointop-sh/cointop/cointop"
|
2020-08-10 01:42:04 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2021-09-30 07:14:27 +00:00
|
|
|
// ResetCmd will wipe cache and config file
|
2020-08-10 01:42:04 +00:00
|
|
|
func ResetCmd() *cobra.Command {
|
2021-09-30 07:14:27 +00:00
|
|
|
config := os.Getenv("COINTOP_CONFIG")
|
|
|
|
cacheDir := os.Getenv("COINTOP_CACHE_DIR")
|
2020-08-10 01:42:04 +00:00
|
|
|
|
|
|
|
resetCmd := &cobra.Command{
|
|
|
|
Use: "reset",
|
|
|
|
Short: "Resets the config and clear the cache",
|
|
|
|
Long: `The reset command resets the config and clears the cache`,
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2021-09-30 07:14:27 +00:00
|
|
|
ct, err := cointop.NewCointop(&cointop.Config{
|
|
|
|
ConfigFilepath: config,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return ct.Reset(&cointop.ResetConfig{
|
2020-08-10 01:42:04 +00:00
|
|
|
Log: true,
|
|
|
|
CacheDir: cacheDir,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
resetCmd.Flags().StringVarP(&cacheDir, "cache-dir", "", cacheDir, "Cache directory")
|
2021-09-30 07:14:27 +00:00
|
|
|
resetCmd.Flags().StringVarP(&config, "config", "c", config, fmt.Sprintf("Config filepath. (default %s)", cointop.DefaultConfigFilepath))
|
2020-08-10 01:42:04 +00:00
|
|
|
|
|
|
|
return resetCmd
|
|
|
|
}
|