package cmd import ( "bufio" "fmt" "os" "strings" "github.com/spf13/cobra" ) var deleteCmd = &cobra.Command{ Use: "delete ", Short: "Delete a part by ID", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { id := args[0] yes, _ := cmd.Flags().GetBool("yes") if !yes { fmt.Printf("Delete part %s? [y/N]: ", id) reader := bufio.NewReader(os.Stdin) answer, err := reader.ReadString('\n') if err != nil { return fmt.Errorf("failed to read input: %w", err) } if !strings.EqualFold(strings.TrimSpace(answer), "y") { fmt.Println("Aborted.") return nil } } if err := GetClient().DeletePart(id); err != nil { return fmt.Errorf("failed to delete part: %w", err) } fmt.Printf("Deleted part %s\n", id) return nil }, } func init() { deleteCmd.Flags().BoolP("yes", "y", false, "Skip confirmation prompt") rootCmd.AddCommand(deleteCmd) }