86 lines
2.2 KiB
Go
86 lines
2.2 KiB
Go
// Copyright 2025 eat-pray-ai & OpenWaygate
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package comment
|
|
|
|
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/comment"
|
|
"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 = "comment-delete"
|
|
deleteConfirm = "Delete comment(s): %s"
|
|
deleteShort = "Delete comments"
|
|
deleteLong = "Delete comments. Use this tool to delete comments by IDs."
|
|
deleteExample = `# Delete a comment by ID
|
|
yutu comment delete --ids abc123
|
|
# Delete multiple comments
|
|
yutu comment 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"},
|
|
},
|
|
},
|
|
}
|
|
|
|
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.GenToolHandlerWithMRTR(
|
|
deleteTool, cobramcp.ConfirmThen(
|
|
func(input comment.Comment) string {
|
|
return fmt.Sprintf(deleteConfirm, strings.Join(input.Ids, ", "))
|
|
},
|
|
func(input comment.Comment, w io.Writer) error {
|
|
return input.Delete(w)
|
|
},
|
|
),
|
|
),
|
|
)
|
|
commentCmd.AddCommand(deleteCmd)
|
|
|
|
deleteCmd.Flags().StringSliceVarP(&ids, "ids", "i", []string{}, idsUsage)
|
|
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 {
|
|
return utils.ConfirmPreRun(
|
|
c, fmt.Sprintf(deleteConfirm, strings.Join(ids, ", ")),
|
|
)
|
|
},
|
|
Run: func(c *cobra.Command, _ []string) {
|
|
input := comment.NewComment(comment.WithIds(ids))
|
|
utils.HandleCmdError(input.Delete(c.OutOrStdout()), c)
|
|
},
|
|
}
|