Files
ax/cmd/delete.go

54 lines
1.1 KiB
Go
Raw Normal View History

2026-03-26 12:48:47 +00:00
package cmd
import (
"axolotl/db"
"axolotl/output"
"bufio"
"fmt"
"os"
"strings"
"github.com/spf13/cobra"
)
var deleteForce bool
var deleteCmd = &cobra.Command{
Use: "delete <id>",
Short: "Delete a node",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
d, err := db.GetDB()
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
id := args[0]
n, err := d.NodeByID(id)
if err != nil {
fmt.Fprintln(os.Stderr, " node not found:", id)
return
}
if !deleteForce {
fmt.Printf(" Delete %s '%s'? [y/N]: ", n.GetType(), n.Title)
reader := bufio.NewReader(os.Stdin)
resp, _ := reader.ReadString('\n')
resp = strings.TrimSpace(strings.ToLower(resp))
if resp != "y" && resp != "yes" {
fmt.Println(" Cancelled.")
return
}
}
if err := d.DeleteNode(id); err != nil {
fmt.Fprintln(os.Stderr, " failed to delete:", err)
return
}
output.PrintDeleted(cmd.OutOrStdout(), id)
},
}
func init() {
rootCmd.AddCommand(deleteCmd)
deleteCmd.Flags().BoolVarP(&deleteForce, "force", "f", false, "skip confirmation")
}