Added create and delete operations for projects and boards with validation and error handling

This commit is contained in:
Steve Cliff
2026-02-17 07:47:49 +00:00
parent c03d05734a
commit c15a48cda3
15 changed files with 571 additions and 4 deletions
+57
View File
@@ -1,8 +1,10 @@
package cmd
import (
"fmt"
"os"
"git.franklin.lab/steve.cliff/pcli/client"
"git.franklin.lab/steve.cliff/pcli/output"
"github.com/spf13/cobra"
)
@@ -56,11 +58,66 @@ var boardActionsCmd = &cobra.Command{
},
}
var boardCreateCmd = &cobra.Command{
Use: "create",
Short: "Create a new board",
RunE: func(cmd *cobra.Command, args []string) error {
project, _ := cmd.Flags().GetString("project")
name, _ := cmd.Flags().GetString("name")
position, _ := cmd.Flags().GetFloat64("position")
// Validate required flags
if project == "" {
return cmd.Usage()
}
if name == "" {
return cmd.Usage()
}
fields := client.BoardCreateFields{
Name: name,
Position: position,
}
board, err := getClient().CreateBoard(getContext(), project, fields)
if err != nil {
return friendlyAPIError(err, "create board", "requires project manager role")
}
return output.Print(board, getFormat(), os.Stdout)
},
}
var boardDeleteCmd = &cobra.Command{
Use: "delete <id>",
Short: "Delete a board",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
err := getClient().DeleteBoard(getContext(), args[0])
if err != nil {
return friendlyAPIError(err, "delete board", "requires project manager role")
}
fmt.Println("Board deleted successfully")
return nil
},
}
func init() {
rootCmd.AddCommand(boardCmd)
boardCmd.AddCommand(boardListCmd)
boardCmd.AddCommand(boardGetCmd)
boardCmd.AddCommand(boardActionsCmd)
boardCmd.AddCommand(boardCreateCmd)
boardCmd.AddCommand(boardDeleteCmd)
boardActionsCmd.Flags().Int("limit", 0, "Limit number of actions (0 = no limit)")
// Flags for board create
boardCreateCmd.Flags().String("project", "", "Project ID (required)")
boardCreateCmd.Flags().String("name", "", "Board name (required)")
boardCreateCmd.Flags().Float64("position", 65536, "Board position (optional, default 65536)")
boardCreateCmd.MarkFlagRequired("project")
boardCreateCmd.MarkFlagRequired("name")
}