Files
nib-v1/cmd/delete.go
T
lerko d715b053e7 refactor(db): thread context.Context through all Store methods
Enables request-scoped cancellation, timeouts, and graceful shutdown
for all database operations across API handlers, CLI commands, and TUI.
2026-05-20 20:51:51 -04:00

49 lines
899 B
Go

package cmd
import (
"fmt"
"github.com/lerko/nib/internal/db"
"github.com/lerko/nib/internal/display"
"github.com/spf13/cobra"
)
var deleteCmd = &cobra.Command{
Use: "delete <id>",
Short: "delete an entity (soft, then hard)",
Args: cobra.ExactArgs(1),
RunE: runDelete,
}
func init() {
rootCmd.AddCommand(deleteCmd)
}
func runDelete(cmd *cobra.Command, args []string) error {
store, err := openStore()
if err != nil {
return err
}
defer store.Close()
id, err := store.Resolve(cmd.Context(), args[0])
if err != nil {
return fmt.Errorf("not_found — no entity with id %s", args[0])
}
result, err := store.SoftDelete(cmd.Context(), id)
if err != nil {
return err
}
shortID := display.FormatID(id)
switch result {
case db.DeletedSoft:
fmt.Printf("deleted %s\n", shortID)
case db.DeletedHard:
fmt.Printf("permanently deleted %s\n", shortID)
}
return nil
}