feat: rename create and delete commands to add and del

This commit is contained in:
2026-03-29 19:46:43 +02:00
parent 68f4b67283
commit 535626d198
5 changed files with 23 additions and 23 deletions

51
cmd/del.go Normal file
View File

@@ -0,0 +1,51 @@
package cmd
import (
"axolotl/db"
"axolotl/output"
"axolotl/service"
"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),
Run: func(cmd *cobra.Command, args []string) {
d, err := db.GetDB()
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
svc := service.NewSQLiteNodeService(d.DB, cfg.GetUser())
n, err := svc.GetByID(args[0])
if err != nil {
fmt.Fprintln(os.Stderr, " node not found:", args[0])
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.")
return
}
}
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)
}
},
}
func init() {
rootCmd.AddCommand(delCmd)
delCmd.Flags().BoolVarP(&dForce, "force", "f", false, "")
}