Files
yutu/cmd/channelSection/delete.go
T

91 lines
2.5 KiB
Go

// Copyright 2025 eat-pray-ai & OpenWaygate
// SPDX-License-Identifier: Apache-2.0
package channelSection
import (
"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/channelSection"
"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 = "channelSection-delete"
deleteIdsUsage = "Delete the channel sections with the given ids"
deleteShort = "Delete channel sections"
deleteLong = "Delete channel sections. Use this tool to delete channel sections by IDs."
deleteExample = `# Delete a channel section by ID
yutu channelSection delete --ids abc123
# Delete multiple channel sections
yutu channelSection delete --ids abc123,def456`
)
var deleteInSchema = &jsonschema.Schema{
Type: "object",
Required: []string{"ids"},
Properties: map[string]*jsonschema.Schema{
"ids": {
Type: "array", Description: deleteIdsUsage,
Items: &jsonschema.Schema{Type: "string"},
},
"on_behalf_of_content_owner": {Type: "string", Description: pkg.OBOCOUsage},
},
}
func init() {
mcp.AddTool(
cmd.Server, &mcp.Tool{
Name: deleteTool, Title: deleteShort, Description: deleteLong,
InputSchema: deleteInSchema, Annotations: &mcp.ToolAnnotations{
DestructiveHint: new(true),
IdempotentHint: false,
OpenWorldHint: new(true),
ReadOnlyHint: false,
},
}, cobramcp.GenToolHandler(
deleteTool,
func(input channelSection.ChannelSection, writer io.Writer) error {
return input.Delete(writer)
},
),
)
channelSectionCmd.AddCommand(deleteCmd)
deleteCmd.Flags().StringSliceVarP(&ids, "ids", "i", []string{}, deleteIdsUsage)
deleteCmd.Flags().StringVarP(
&onBehalfOfContentOwner, "onBehalfOfContentOwner", "b", "", pkg.OBOCOUsage,
)
_ = deleteCmd.MarkFlagRequired("ids")
cmd.AddMutationFlags(deleteCmd)
}
var deleteCmd = &cobra.Command{
Use: "delete",
Short: deleteShort,
Long: deleteLong,
Example: deleteExample,
Run: func(c *cobra.Command, args []string) {
err := cmd.Confirm(
c, "Would delete channel section(s): %s", strings.Join(ids, ", "),
)
if err != nil {
utils.HandleCmdError(err, c)
return
}
input := channelSection.NewChannelSection(
channelSection.WithIds(ids),
channelSection.WithOnBehalfOfContentOwner(onBehalfOfContentOwner),
)
utils.HandleCmdError(input.Delete(c.OutOrStdout()), c)
},
}