d715b053e7
Enables request-scoped cancellation, timeouts, and graceful shutdown for all database operations across API handlers, CLI commands, and TUI.
44 lines
888 B
Go
44 lines
888 B
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/lerko/nib/internal/db"
|
|
"github.com/lerko/nib/internal/display"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var demoteCmd = &cobra.Command{
|
|
Use: "demote <id>",
|
|
Short: "strip card layer, return to fluid",
|
|
Args: cobra.ExactArgs(1),
|
|
RunE: runDemote,
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(demoteCmd)
|
|
}
|
|
|
|
func runDemote(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])
|
|
}
|
|
|
|
if err := store.Demote(cmd.Context(), id); err != nil {
|
|
if err == db.ErrAlreadyFluid {
|
|
return fmt.Errorf("invalid_demote — entity %s is already fluid", display.FormatID(id))
|
|
}
|
|
return err
|
|
}
|
|
|
|
fmt.Printf("demoted %s → note\n", display.FormatID(id))
|
|
return nil
|
|
}
|