Files
ax/cmd/del.go

50 lines
1.1 KiB
Go
Raw Normal View History

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"
)
var dForce bool
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) {
svc, err := service.GetNodeService(cfg)
2026-03-26 12:48:47 +00:00
if err != nil {
fmt.Fprintln(os.Stderr, "failed to create service: %v", err)
2026-03-26 12:48:47 +00:00
return
}
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 {
fmt.Fprintln(os.Stderr, " node not found:", args[0])
2026-03-26 12:48:47 +00:00
return
}
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-29 18:58:34 +02:00
if err := svc.Delete(args[0]); err != nil {
fmt.Fprintln(os.Stderr, "failed to delete: ", err)
} else {
output.PrintAction(cmd.OutOrStdout(), "Deleted", args[0], true)
2026-03-26 12:48:47 +00:00
}
},
}
func init() {
rootCmd.AddCommand(delCmd)
delCmd.Flags().BoolVarP(&dForce, "force", "f", false, "")
2026-03-26 12:48:47 +00:00
}