2026-03-26 12:48:47 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"axolotl/output"
|
2026-03-29 18:58:34 +02:00
|
|
|
"axolotl/service"
|
2026-03-26 12:48:47 +00:00
|
|
|
"bufio"
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
)
|
|
|
|
|
|
2026-03-27 02:11:46 +01:00
|
|
|
var dForce bool
|
2026-03-29 19:46:43 +02:00
|
|
|
var delCmd = &cobra.Command{
|
|
|
|
|
Use: "del <id>", Short: "Delete a node", Args: cobra.ExactArgs(1),
|
2026-03-26 12:48:47 +00:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2026-03-29 21:24:09 +02:00
|
|
|
svc, err := service.GetNodeService(cfg)
|
2026-03-26 12:48:47 +00:00
|
|
|
if err != nil {
|
2026-03-29 23:16:44 +02:00
|
|
|
fmt.Fprintln(os.Stderr, err)
|
2026-03-26 12:48:47 +00:00
|
|
|
return
|
|
|
|
|
}
|
2026-03-29 23:16:44 +02:00
|
|
|
|
2026-03-29 18:58:34 +02:00
|
|
|
n, err := svc.GetByID(args[0])
|
2026-03-26 12:48:47 +00:00
|
|
|
if err != nil {
|
2026-03-31 22:36:49 +02:00
|
|
|
fmt.Fprintf(os.Stderr, "node not found: %s\n", args[0])
|
|
|
|
|
os.Exit(1)
|
2026-03-26 12:48:47 +00:00
|
|
|
}
|
2026-03-27 02:11:46 +01:00
|
|
|
|
|
|
|
|
if !dForce {
|
|
|
|
|
fmt.Printf("Delete %s '%s'? [y/N]: ", n.GetProperty("type"), n.Title)
|
|
|
|
|
r, _ := bufio.NewReader(os.Stdin).ReadString('\n')
|
|
|
|
|
if r = strings.TrimSpace(strings.ToLower(r)); r != "y" && r != "yes" {
|
|
|
|
|
fmt.Println("Cancelled.")
|
2026-03-26 12:48:47 +00:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-27 02:11:46 +01:00
|
|
|
|
2026-03-29 18:58:34 +02:00
|
|
|
if err := svc.Delete(args[0]); err != nil {
|
2026-03-29 23:16:44 +02:00
|
|
|
fmt.Fprintf(os.Stderr, "failed to delete: %v", err)
|
2026-03-27 02:11:46 +01:00
|
|
|
} else {
|
|
|
|
|
output.PrintAction(cmd.OutOrStdout(), "Deleted", args[0], true)
|
2026-03-26 12:48:47 +00:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func init() {
|
2026-03-29 19:46:43 +02:00
|
|
|
rootCmd.AddCommand(delCmd)
|
|
|
|
|
delCmd.Flags().BoolVarP(&dForce, "force", "f", false, "")
|
2026-03-26 12:48:47 +00:00
|
|
|
}
|