Files
yutu/cmd/liveStream/delete.go
T

97 lines
2.7 KiB
Go

// Copyright 2026 eat-pray-ai & OpenWaygate
// SPDX-License-Identifier: Apache-2.0
package liveStream
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/liveStream"
"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 = "liveStream-delete"
deleteIdsUsage = "IDs of the live streams to delete"
deleteShort = "Delete live streams"
deleteLong = "Delete live streams. Use this tool to delete live streams by their IDs."
deleteExample = `# Delete a live stream by ID
yutu liveStream delete --ids stream123
# Delete multiple live streams
yutu liveStream delete --ids stream123,stream456`
)
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},
"on_behalf_of_content_owner_channel": {
Type: "string", Description: obococUsage,
},
},
}
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 liveStream.LiveStream, writer io.Writer) error {
return input.Delete(writer)
},
),
)
liveStreamCmd.AddCommand(deleteCmd)
deleteCmd.Flags().StringSliceVarP(&ids, "ids", "i", []string{}, deleteIdsUsage)
deleteCmd.Flags().StringVarP(
&onBehalfOfContentOwner, "onBehalfOfContentOwner", "b", "", pkg.OBOCOUsage,
)
deleteCmd.Flags().StringVarP(
&onBehalfOfContentOwnerChannel, "onBehalfOfContentOwnerChannel", "B", "",
obococUsage,
)
_ = 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 live stream(s): %s", strings.Join(ids, ", "),
)
if err != nil {
utils.HandleCmdError(err, c)
return
}
input := liveStream.NewLiveStream(
liveStream.WithIds(ids),
liveStream.WithOnBehalfOfContentOwner(onBehalfOfContentOwner),
liveStream.WithOnBehalfOfContentOwnerChannel(onBehalfOfContentOwnerChannel),
)
utils.HandleCmdError(input.Delete(c.OutOrStdout()), c)
},
}