Released v1
This commit is contained in:
+108
@@ -0,0 +1,108 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.franklin.lab/steve.cliff/pcli/output"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var commentCmd = &cobra.Command{
|
||||
Use: "comment",
|
||||
Short: "Manage comments",
|
||||
Long: "Commands for managing Planka card comments",
|
||||
}
|
||||
|
||||
var commentListCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List comments for a card",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cardId, _ := cmd.Flags().GetString("card")
|
||||
limit, _ := cmd.Flags().GetInt("limit")
|
||||
|
||||
if cardId == "" {
|
||||
return fmt.Errorf("--card is required")
|
||||
}
|
||||
|
||||
comments, err := getClient().ListComments(getContext(), cardId, limit)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return output.Print(comments, getFormat(), os.Stdout)
|
||||
},
|
||||
}
|
||||
|
||||
var commentCreateCmd = &cobra.Command{
|
||||
Use: "create",
|
||||
Short: "Create a new comment",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cardId, _ := cmd.Flags().GetString("card")
|
||||
text, _ := cmd.Flags().GetString("text")
|
||||
|
||||
if cardId == "" {
|
||||
return fmt.Errorf("--card is required")
|
||||
}
|
||||
if text == "" {
|
||||
return fmt.Errorf("--text is required")
|
||||
}
|
||||
|
||||
comment, err := getClient().CreateComment(getContext(), cardId, text)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return output.Print(comment, getFormat(), os.Stdout)
|
||||
},
|
||||
}
|
||||
|
||||
var commentUpdateCmd = &cobra.Command{
|
||||
Use: "update <id>",
|
||||
Short: "Update a comment",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
text, _ := cmd.Flags().GetString("text")
|
||||
|
||||
if text == "" {
|
||||
return fmt.Errorf("--text is required")
|
||||
}
|
||||
|
||||
comment, err := getClient().UpdateComment(getContext(), args[0], text)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return output.Print(comment, getFormat(), os.Stdout)
|
||||
},
|
||||
}
|
||||
|
||||
var commentDeleteCmd = &cobra.Command{
|
||||
Use: "delete <id>",
|
||||
Short: "Delete a comment",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
err := getClient().DeleteComment(getContext(), args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return output.Print(map[string]string{"status": "deleted"}, getFormat(), os.Stdout)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(commentCmd)
|
||||
commentCmd.AddCommand(commentListCmd)
|
||||
commentCmd.AddCommand(commentCreateCmd)
|
||||
commentCmd.AddCommand(commentUpdateCmd)
|
||||
commentCmd.AddCommand(commentDeleteCmd)
|
||||
|
||||
commentListCmd.Flags().String("card", "", "Card ID (required)")
|
||||
commentListCmd.Flags().Int("limit", 0, "Limit number of comments (0 = no limit)")
|
||||
|
||||
commentCreateCmd.Flags().String("card", "", "Card ID (required)")
|
||||
commentCreateCmd.Flags().String("text", "", "Comment text (required)")
|
||||
|
||||
commentUpdateCmd.Flags().String("text", "", "Comment text (required)")
|
||||
}
|
||||
Reference in New Issue
Block a user