* ♻️ Refactor IsInteractive to accept any * ♻️ Simplify Confirm to return bool * ♻️ Use simplified Confirm in mutation commands * 🔧 Update MODULE.bazel for go tool * ✨ Add ConfirmPreRun utility * ♻️ Migrate mutation commands to ConfirmPreRun * 🎨 Fix alignment and trailing newlines
93 lines
2.6 KiB
Go
93 lines
2.6 KiB
Go
// Copyright 2025 eat-pray-ai & OpenWaygate
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package playlistImage
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"strings"
|
|
|
|
cobramcp "github.com/eat-pray-ai/cobra-mcp"
|
|
"github.com/eat-pray-ai/yutu/cmd"
|
|
"github.com/eat-pray-ai/yutu/pkg"
|
|
"github.com/eat-pray-ai/yutu/pkg/playlistImage"
|
|
"github.com/eat-pray-ai/yutu/pkg/utils"
|
|
"github.com/google/jsonschema-go/jsonschema"
|
|
"github.com/modelcontextprotocol/go-sdk/mcp"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
const (
|
|
deleteTool = "playlistImage-delete"
|
|
deleteShort = "Delete playlist images"
|
|
deleteLong = "Delete playlist images. Use this tool to delete playlist images by IDs."
|
|
deleteExample = `# Delete a playlist image by ID
|
|
yutu playlistImage delete --ids abc123
|
|
# Delete multiple playlist images
|
|
yutu playlistImage delete --ids abc123,def456`
|
|
)
|
|
|
|
var deleteInSchema = &jsonschema.Schema{
|
|
Type: "object",
|
|
Required: []string{"ids"},
|
|
Properties: map[string]*jsonschema.Schema{
|
|
"ids": {
|
|
Type: "array", Description: idsUsage,
|
|
Items: &jsonschema.Schema{Type: "string"},
|
|
},
|
|
"on_behalf_of_content_owner": {Type: "string", Description: pkg.OBOCOUsage},
|
|
"confirmed": {Type: "boolean", Description: pkg.ConfirmedUsage},
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
mcp.AddTool(
|
|
cmd.Server, &mcp.Tool{
|
|
Name: deleteTool, Title: deleteShort, Description: deleteLong,
|
|
InputSchema: deleteInSchema, Annotations: &mcp.ToolAnnotations{
|
|
DestructiveHint: new(true),
|
|
IdempotentHint: true,
|
|
OpenWorldHint: new(true),
|
|
ReadOnlyHint: false,
|
|
},
|
|
}, cobramcp.GenToolHandler(
|
|
deleteTool,
|
|
func(input playlistImage.PlaylistImage, writer io.Writer) error {
|
|
if !input.Confirmed {
|
|
return utils.ErrNotConfirmed
|
|
}
|
|
return input.Delete(writer)
|
|
},
|
|
),
|
|
)
|
|
playlistImageCmd.AddCommand(deleteCmd)
|
|
|
|
deleteCmd.Flags().StringSliceVarP(&ids, "ids", "i", []string{}, idsUsage)
|
|
deleteCmd.Flags().StringVarP(
|
|
&onBehalfOfContentOwner, "onBehalfOfContentOwner", "b", "", pkg.OBOCOUsage,
|
|
)
|
|
deleteCmd.Flags().Bool("yes", false, pkg.ConfirmedUsage)
|
|
_ = deleteCmd.MarkFlagRequired("ids")
|
|
}
|
|
|
|
var deleteCmd = &cobra.Command{
|
|
Use: "delete",
|
|
Short: deleteShort,
|
|
Long: deleteLong,
|
|
Example: deleteExample,
|
|
PreRunE: func(c *cobra.Command, _ []string) error {
|
|
msg := fmt.Sprintf(
|
|
"Would delete playlist image(s): %s", strings.Join(ids, ", "),
|
|
)
|
|
return utils.ConfirmPreRun(c, msg)
|
|
},
|
|
Run: func(c *cobra.Command, _ []string) {
|
|
input := playlistImage.NewPlaylistImage(
|
|
playlistImage.WithIds(ids),
|
|
playlistImage.WithOnBehalfOfContentOwner(onBehalfOfContentOwner),
|
|
)
|
|
utils.HandleCmdError(input.Delete(c.OutOrStdout()), c)
|
|
},
|
|
}
|