/* Copyright © 2025 Jake jake.young.dev@gmail.com */ package cmd import ( "bufio" "fmt" "os" "strings" "code.jakeyoungdev.com/jake/mctl/cmd/command" "code.jakeyoungdev.com/jake/mctl/database" "github.com/spf13/cobra" ) // destroyCmd represents the destroy command var destroyCmd = &cobra.Command{ Use: "destroy", Short: "clears all configuration", Long: `clear all data and drop database tables, this will delete all previously saved data and the 'inti' command must be run again before use`, SilenceUsage: true, Run: func(cmd *cobra.Command, args []string) { scanner := bufio.NewScanner(os.Stdin) fmt.Printf("Are you sure you want to destroy your config? (yes|no): ") if scanner.Scan() { if strings.EqualFold(scanner.Text(), "yes") { db, err := database.New() cobra.CheckErr(err) defer db.Close() err = db.Destroy() if err != nil { if err.Error() == command.ErrInit { fmt.Println(command.ErrInitRsp) return } } cobra.CheckErr(err) fmt.Println("Configuration is cleared, the 'init' command must be run again.") } } else { return } }, } func init() { rootCmd.AddCommand(destroyCmd) }