Files
pcli/cmd/board.go
T
2026-03-02 12:06:07 +00:00

124 lines
3.0 KiB
Go

package cmd
import (
"fmt"
"os"
"git.franklin.lab/steve.cliff/pcli/client"
"git.franklin.lab/steve.cliff/pcli/output"
"github.com/spf13/cobra"
)
var boardCmd = &cobra.Command{
Use: "board",
Short: "Manage boards",
Long: "Commands for managing Planka boards",
}
var boardListCmd = &cobra.Command{
Use: "list",
Short: "List all accessible boards",
RunE: func(cmd *cobra.Command, args []string) error {
boards, err := getClient().ListBoards(getContext())
if err != nil {
return err
}
return output.Print(boards, getFormat(), os.Stdout)
},
}
var boardGetCmd = &cobra.Command{
Use: "get <id>",
Short: "Get a board by ID",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
board, err := getClient().GetBoard(getContext(), args[0])
if err != nil {
return err
}
return output.Print(board, getFormat(), os.Stdout)
},
}
var boardActionsCmd = &cobra.Command{
Use: "actions <id>",
Short: "List actions for a board",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
limit, _ := cmd.Flags().GetInt("limit")
actions, err := getClient().ListBoardActions(getContext(), args[0], limit)
if err != nil {
return err
}
return output.Print(actions, getFormat(), os.Stdout)
},
}
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")
}