Added list management commands, board filtering by project name, and enhanced skill documentation with bootstrap workflow and error handling patterns. Also added plumbing in to "pcli" binary for status syncing with Planka
This commit is contained in:
@@ -3,6 +3,7 @@ package cmd
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"git.franklin.lab/steve.cliff/pcli/client"
|
||||
"git.franklin.lab/steve.cliff/pcli/output"
|
||||
@@ -15,15 +16,47 @@ var boardCmd = &cobra.Command{
|
||||
Long: "Commands for managing Planka boards",
|
||||
}
|
||||
|
||||
func resolveProjectNameToID(projectName string) (string, error) {
|
||||
projects, err := getClient().ListProjects(getContext())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
for _, project := range projects {
|
||||
if strings.EqualFold(project.Name, projectName) {
|
||||
return project.ID, nil
|
||||
}
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("project not found: %s", projectName)
|
||||
}
|
||||
|
||||
var boardListCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List all accessible boards",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
projectName, _ := cmd.Flags().GetString("project")
|
||||
|
||||
boards, err := getClient().ListBoards(getContext())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if projectName != "" {
|
||||
projectID, err := resolveProjectNameToID(projectName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var filteredBoards []interface{}
|
||||
for _, board := range boards {
|
||||
if board.ProjectID == projectID {
|
||||
filteredBoards = append(filteredBoards, board)
|
||||
}
|
||||
}
|
||||
return output.Print(filteredBoards, getFormat(), os.Stdout)
|
||||
}
|
||||
|
||||
return output.Print(boards, getFormat(), os.Stdout)
|
||||
},
|
||||
}
|
||||
@@ -111,6 +144,8 @@ func init() {
|
||||
boardCmd.AddCommand(boardCreateCmd)
|
||||
boardCmd.AddCommand(boardDeleteCmd)
|
||||
|
||||
boardListCmd.Flags().String("project", "", "Filter boards by project name")
|
||||
|
||||
boardActionsCmd.Flags().Int("limit", 0, "Limit number of actions (0 = no limit)")
|
||||
|
||||
// Flags for board create
|
||||
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.franklin.lab/steve.cliff/pcli/client"
|
||||
"git.franklin.lab/steve.cliff/pcli/output"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var listCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "Manage lists (board columns)",
|
||||
Long: "Commands for managing Planka lists (board columns)",
|
||||
}
|
||||
|
||||
var listCreateCmd = &cobra.Command{
|
||||
Use: "create",
|
||||
Short: "Create a new list",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
board, _ := cmd.Flags().GetString("board")
|
||||
name, _ := cmd.Flags().GetString("name")
|
||||
listType, _ := cmd.Flags().GetString("type")
|
||||
position, _ := cmd.Flags().GetFloat64("position")
|
||||
|
||||
// Validate required flags
|
||||
if board == "" {
|
||||
return cmd.Usage()
|
||||
}
|
||||
if name == "" {
|
||||
return cmd.Usage()
|
||||
}
|
||||
if listType == "" {
|
||||
listType = "active" // default to active
|
||||
}
|
||||
|
||||
fields := client.ListCreateFields{
|
||||
Name: name,
|
||||
Type: listType,
|
||||
Position: position,
|
||||
}
|
||||
|
||||
list, err := getClient().CreateList(getContext(), board, fields)
|
||||
if err != nil {
|
||||
return friendlyAPIError(err, "create list", "requires board editor role")
|
||||
}
|
||||
|
||||
return output.Print(list, getFormat(), os.Stdout)
|
||||
},
|
||||
}
|
||||
|
||||
var listGetCmd = &cobra.Command{
|
||||
Use: "get <id>",
|
||||
Short: "Get a list by ID",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
list, err := getClient().GetList(getContext(), args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return output.Print(list, getFormat(), os.Stdout)
|
||||
},
|
||||
}
|
||||
|
||||
var listUpdateCmd = &cobra.Command{
|
||||
Use: "update <id>",
|
||||
Short: "Update a list",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
fields := client.ListUpdateFields{}
|
||||
|
||||
if name, _ := cmd.Flags().GetString("name"); cmd.Flags().Changed("name") {
|
||||
fields.Name = &name
|
||||
}
|
||||
if listType, _ := cmd.Flags().GetString("type"); cmd.Flags().Changed("type") {
|
||||
fields.Type = &listType
|
||||
}
|
||||
if color, _ := cmd.Flags().GetString("color"); cmd.Flags().Changed("color") {
|
||||
fields.Color = &color
|
||||
}
|
||||
if pos, _ := cmd.Flags().GetFloat64("position"); cmd.Flags().Changed("position") {
|
||||
fields.Position = &pos
|
||||
}
|
||||
if board, _ := cmd.Flags().GetString("board"); cmd.Flags().Changed("board") {
|
||||
fields.BoardID = &board
|
||||
}
|
||||
|
||||
// Check if at least one field is being updated
|
||||
if fields.Name == nil && fields.Type == nil && fields.Color == nil && fields.Position == nil && fields.BoardID == nil {
|
||||
return fmt.Errorf("at least one field must be specified for update")
|
||||
}
|
||||
|
||||
list, err := getClient().UpdateList(getContext(), args[0], fields)
|
||||
if err != nil {
|
||||
return friendlyAPIError(err, "update list", "requires board editor role")
|
||||
}
|
||||
|
||||
return output.Print(list, getFormat(), os.Stdout)
|
||||
},
|
||||
}
|
||||
|
||||
var listDeleteCmd = &cobra.Command{
|
||||
Use: "delete <id>",
|
||||
Short: "Delete a list",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
err := getClient().DeleteList(getContext(), args[0])
|
||||
if err != nil {
|
||||
return friendlyAPIError(err, "delete list", "requires board editor role")
|
||||
}
|
||||
|
||||
fmt.Println("List deleted successfully")
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(listCmd)
|
||||
listCmd.AddCommand(listCreateCmd)
|
||||
listCmd.AddCommand(listGetCmd)
|
||||
listCmd.AddCommand(listUpdateCmd)
|
||||
listCmd.AddCommand(listDeleteCmd)
|
||||
|
||||
// Flags for list create
|
||||
listCreateCmd.Flags().String("board", "", "Board ID (required)")
|
||||
listCreateCmd.Flags().String("name", "", "List name (required)")
|
||||
listCreateCmd.Flags().String("type", "active", "List type (active|closed, default: active)")
|
||||
listCreateCmd.Flags().Float64("position", 65536, "List position (optional, default 65536)")
|
||||
|
||||
listCreateCmd.MarkFlagRequired("board")
|
||||
listCreateCmd.MarkFlagRequired("name")
|
||||
|
||||
// Flags for list update
|
||||
listUpdateCmd.Flags().String("name", "", "List name")
|
||||
listUpdateCmd.Flags().String("type", "", "List type (active|closed)")
|
||||
listUpdateCmd.Flags().String("color", "", "List color")
|
||||
listUpdateCmd.Flags().Float64("position", 0, "List position")
|
||||
listUpdateCmd.Flags().String("board", "", "Move list to different board (Board ID)")
|
||||
}
|
||||
Reference in New Issue
Block a user