Skip to content

Commit

Permalink
complete get list(s) options
Browse files Browse the repository at this point in the history
  • Loading branch information
fantasticrabbit committed Nov 15, 2021
1 parent 314bc2c commit b9645ff
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 65 deletions.
43 changes: 33 additions & 10 deletions cmd/getlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,53 @@ import (
)

var listCmd = &cobra.Command{
Use: "list",
Short: "get data for a list of tasks by supplying it's list id",
Long: `Request JSON data for a list of tasks in an authorized Clickup workspace`,
Use: "list {LISTID | --folder=FOLDERID | --space=SPACEID} [-a]",
Short: "get data for a list object(s) by supplying it's list id",
Long: `Request JSON data for a list object or folders of list objects
in an authorized Clickup workspace`,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
switch {
case len(args) == 0:
if viper.GetString("folder") != "" && viper.GetString("space") != "" {
return errors.New("do not provide both folder and space flags")
}
return nil

case len(args) == 1:
if viper.GetString("folder")+viper.GetString("space") != "" {
return errors.New("do not provide folder or space flags if outputting a specific list")
}
return nil

default:
return errors.New("incorrect number of arguments")

}
return nil
},
PreRun: func(cmd *cobra.Command, args []string) {
checkToken()
},
Run: func(cmd *cobra.Command, args []string) {
viper.BindPFlag("custom", cmd.Flags().Lookup("custom"))
viper.BindPFlag("subtasks", cmd.Flags().Lookup("subtasks"))

var l = internal.ListRequest{
ListID: string(args[0]),
Subtasks: viper.GetBool("subtasks"),
l := internal.ListRequest{
FolderID: viper.GetString("folder"),
SpaceID: viper.GetString("space"),
Archived: viper.GetBool("archived"),
}
if len(args) == 1 {
l.ListID = args[0]
}

fmt.Println(internal.FormatJSON(l.GetJSON(l.BuildPath())))
},
}

func init() {
getCmd.AddCommand(listCmd)
listCmd.Flags().BoolP("archived", "a", false, "include archived lists in output")
listCmd.Flags().StringP("folder", "", "", "get data on a group of lists by folder")
listCmd.Flags().StringP("space", "", "", "get data on a group of lists by workspace")
viper.BindPFlag("archived", listCmd.Flags().Lookup("archived"))
viper.BindPFlag("folder", listCmd.Flags().Lookup("folder"))
viper.BindPFlag("space", listCmd.Flags().Lookup("space"))
}
68 changes: 13 additions & 55 deletions internal/getlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,31 @@ package internal

import (
"fmt"
"net/url"
)

type ListRequest struct {
ListID string
Archived bool
Page int
Order_By string
Reverse bool
Subtasks bool
Statuses []string
Include_Closed bool
Assignees []string
Due_Date_gt int
Due_Date_lt int
Date_Created_gt int
Date_Created_lt int
Date_Updated_gt int
Date_Updated_lt int
CustomFields string
ListID string
FolderID string
SpaceID string
Archived bool
}

//BuildPath creates the API path for a task request
func (l ListRequest) BuildPath() string {
noflags := true

switch {
case noflags:
return fmt.Sprintf("%s/list/%s/", prodAPIbaseV2, l.ListID)

case l.FolderID != "":
return fmt.Sprintf("%s/folder/%s/list?archived=%t", prodAPIbaseV2, l.FolderID, l.Archived)

case l.SpaceID != "":
return fmt.Sprintf("%s/space/%s/list?archived=%t", prodAPIbaseV2, l.SpaceID, l.Archived)

default:
return url.PathEscape(fmt.Sprintf("%s/list/%s/?task"+
"?archived=%t"+
"&page=%d"+
"&order_by=%s"+
"&reverse=%t"+
"&subtasks=%t"+
"&statuses[]=%v"+
"&include_closed=%t"+
"&assignees[]=%v"+
"&due_date_gt=%d"+
"&due_date_lt=%d"+
"&date_created_gt=%d"+
"&date_created_lt=%d"+
"&date_updated_gt=%d"+
"&date_updated_lt=%d"+
"&custom_fields[]=%v",
prodAPIbaseV2,
l.ListID,
l.Archived,
l.Page,
l.Order_By,
l.Reverse,
l.Subtasks,
l.Statuses,
l.Include_Closed,
l.Assignees,
l.Due_Date_gt,
l.Due_Date_lt,
l.Date_Created_gt,
l.Date_Created_lt,
l.Date_Updated_gt,
l.Date_Updated_lt,
l.CustomFields))
return fmt.Sprintf("%s/list/%s/", prodAPIbaseV2, l.ListID)
}
}

//GetJSON accepts an API path and returns byte payload of JSON data
func (t ListRequest) GetJSON(apiPath string) string {
func (t ListRequest) GetJSON(apiPath string) []byte {
return getJSON(apiPath)
}

0 comments on commit b9645ff

Please sign in to comment.