From 4f28f8e434cff0aa8284d562aea10f37c0d0be1e Mon Sep 17 00:00:00 2001 From: HacDan Date: Sun, 9 Apr 2023 23:53:29 -0400 Subject: [PATCH 1/4] chore(dep upgrade): Update urfave/cli to V2 --- add.go | 4 +- add_project.go | 4 +- close.go | 4 +- completed.go | 6 +-- delete.go | 4 +- format.go | 10 ++--- go.mod | 3 +- go.sum | 8 ++-- karma.go | 2 +- labels.go | 4 +- list.go | 4 +- main.go | 108 +++++++++++++++++++++++++++---------------------- modify.go | 2 +- projects.go | 6 +-- quick.go | 2 +- show.go | 4 +- sync.go | 2 +- 17 files changed, 94 insertions(+), 83 deletions(-) diff --git a/add.go b/add.go index b750db8..913d6c6 100644 --- a/add.go +++ b/add.go @@ -4,8 +4,8 @@ import ( "context" "strings" - "github.com/sachaos/todoist/lib" - "github.com/urfave/cli" + todoist "github.com/sachaos/todoist/lib" + "github.com/urfave/cli/v2" ) var priorityMapping = map[int]int{ diff --git a/add_project.go b/add_project.go index 8d90970..e6fe0be 100644 --- a/add_project.go +++ b/add_project.go @@ -3,8 +3,8 @@ package main import ( "context" - "github.com/sachaos/todoist/lib" - "github.com/urfave/cli" + todoist "github.com/sachaos/todoist/lib" + "github.com/urfave/cli/v2" ) func AddProject(c *cli.Context) error { diff --git a/close.go b/close.go index 385faba..635d62c 100644 --- a/close.go +++ b/close.go @@ -3,14 +3,14 @@ package main import ( "context" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func Close(c *cli.Context) error { client := GetClient(c) item_ids := []string{} - for _, arg := range c.Args() { + for _, arg := range c.Args().Slice() { item_ids = append(item_ids, arg) } diff --git a/completed.go b/completed.go index 91c043a..2b5f14f 100644 --- a/completed.go +++ b/completed.go @@ -3,9 +3,9 @@ package main import ( "context" - "github.com/sachaos/todoist/lib" + todoist "github.com/sachaos/todoist/lib" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func CompletedList(c *cli.Context) error { @@ -27,7 +27,7 @@ func CompletedList(c *cli.Context) error { defer writer.Flush() - if c.GlobalBool("header") { + if c.Bool("header") { writer.Write([]string{"ID", "CompletedDate", "Project", "Content"}) } diff --git a/delete.go b/delete.go index a4de5d7..16daff7 100644 --- a/delete.go +++ b/delete.go @@ -3,14 +3,14 @@ package main import ( "context" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func Delete(c *cli.Context) error { client := GetClient(c) item_ids := []string{} - for _, arg := range c.Args() { + for _, arg := range c.Args().Slice() { item_id, err := client.CompleteItemIDByPrefix(arg) if err != nil { return err diff --git a/format.go b/format.go index c5fe328..985ccea 100644 --- a/format.go +++ b/format.go @@ -6,8 +6,8 @@ import ( "time" "github.com/fatih/color" - "github.com/sachaos/todoist/lib" - "github.com/urfave/cli" + todoist "github.com/sachaos/todoist/lib" + "github.com/urfave/cli/v2" ) func ColorList() []color.Attribute { @@ -46,10 +46,10 @@ func IdFormat(carrier todoist.IDCarrier) string { } func ContentPrefix(store *todoist.Store, item *todoist.Item, depth int, c *cli.Context) (prefix string) { - if c.GlobalBool("indent") { + if c.Bool("indent") { prefix = prefix + strings.Repeat(" ", depth) } - if c.GlobalBool("namespace") { + if c.Bool("namespace") { parents := todoist.SearchItemParents(store, item) for _, parent := range parents { prefix = prefix + parent.Content + ":" @@ -95,7 +95,7 @@ func ProjectFormat(id string, store *todoist.Store, projectColorHash map[string] } projectName := project.Name - if c.GlobalBool("project-namespace") { + if c.Bool("project-namespace") { parentProjects := todoist.SearchProjectParents(store, project) for _, project := range parentProjects { namePrefix = namePrefix + project.Name + ":" diff --git a/go.mod b/go.mod index 42edc1a..991c2ea 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/rkoesters/xdg v0.0.0-20181125232953-edd15b846f9b github.com/spf13/viper v1.15.0 github.com/stretchr/testify v1.8.1 - github.com/urfave/cli v1.22.12 + github.com/urfave/cli/v2 v2.25.1 ) require ( @@ -30,6 +30,7 @@ require ( github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/subosito/gotenv v1.4.2 // indirect + github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect golang.org/x/sys v0.3.0 // indirect golang.org/x/text v0.5.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect diff --git a/go.sum b/go.sum index 94b2630..a318385 100644 --- a/go.sum +++ b/go.sum @@ -37,7 +37,6 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8= github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo= @@ -188,8 +187,10 @@ github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKs github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8= github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= -github.com/urfave/cli v1.22.12 h1:igJgVw1JdKH+trcLWLeLwZjU9fEfPesQ+9/e4MQ44S8= -github.com/urfave/cli v1.22.12/go.mod h1:sSBEIC79qR6OvcmsD4U3KABeOTxDqQtdDnaFuUN30b8= +github.com/urfave/cli/v2 v2.25.1 h1:zw8dSP7ghX0Gmm8vugrs6q9Ku0wzweqPyshy+syu9Gw= +github.com/urfave/cli/v2 v2.25.1/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -488,7 +489,6 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/karma.go b/karma.go index 66dad3f..5bfe5c5 100644 --- a/karma.go +++ b/karma.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func Karma(c *cli.Context) error { diff --git a/labels.go b/labels.go index 4c713c8..94cceae 100644 --- a/labels.go +++ b/labels.go @@ -4,7 +4,7 @@ import ( "os" "text/tabwriter" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func Labels(c *cli.Context) error { @@ -15,7 +15,7 @@ func Labels(c *cli.Context) error { defer writer.Flush() - if c.GlobalBool("header") { + if c.Bool("header") { writer.Write([]string{"ID", "Name"}) } diff --git a/list.go b/list.go index 05785cc..3aac08f 100644 --- a/list.go +++ b/list.go @@ -6,7 +6,7 @@ import ( "github.com/acarl005/stripansi" todoist "github.com/sachaos/todoist/lib" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func traverseItems(item *todoist.Item, f func(item *todoist.Item, depth int), depth int) { @@ -82,7 +82,7 @@ func List(c *cli.Context) error { defer writer.Flush() - if c.GlobalBool("header") { + if c.Bool("header") { writer.Write([]string{"ID", "Priority", "DueDate", "Project", "Labels", "Content"}) } diff --git a/main.go b/main.go index cb5f327..119d7d7 100644 --- a/main.go +++ b/main.go @@ -13,9 +13,9 @@ import ( "github.com/fatih/color" "github.com/rkoesters/xdg/basedir" - "github.com/sachaos/todoist/lib" + todoist "github.com/sachaos/todoist/lib" "github.com/spf13/viper" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var ( @@ -46,73 +46,83 @@ func main() { app.EnableBashCompletion = true contentFlag := cli.StringFlag{ - Name: "content, c", - Usage: "content", + Name: "content", + Aliases: []string{"c"}, + Usage: "content", } priorityFlag := cli.IntFlag{ - Name: "priority, p", - Value: 4, - Usage: "priority (1-4)", + Name: "priority", + Aliases: []string{"p"}, + Value: 4, + Usage: "priority (1-4)", } labelNamesFlag := cli.StringFlag{ - Name: "label-names, L", - Usage: "label names (separated by ,)", + Name: "label-names", + Aliases: []string{"L"}, + Usage: "label names (separated by ,)", } projectIDFlag := cli.IntFlag{ - Name: "project-id, P", - Usage: "project id", + Name: "project-id", + Aliases: []string{"P"}, + Usage: "project id", } projectNameFlag := cli.StringFlag{ - Name: "project-name, N", - Usage: "project name", + Name: "project-name", + Aliases: []string{"N"}, + Usage: "project name", } dateFlag := cli.StringFlag{ - Name: "date, d", - Usage: "date string (today, 2020/04/02, 2020/03/21 18:00)", + Name: "date", + Aliases: []string{"d"}, + Usage: "date string (today, 2020/04/02, 2020/03/21 18:00)", } browseFlag := cli.BoolFlag{ - Name: "browse, o", - Usage: "when contain URL, open it", + Name: "browse", + Aliases: []string{"o"}, + Usage: "when contain URL, open it", } filterFlag := cli.StringFlag{ - Name: "filter, f", - Usage: "filter expression", + Name: "filter", + Aliases: []string{"f"}, + Usage: "filter expression", } sortPriorityFlag := cli.BoolFlag{ - Name: "priority, p", - Usage: "sort the output by priority", + Name: "priority", + Aliases: []string{"p"}, + Usage: "sort the output by priority", } reminderFlg := cli.BoolFlag{ - Name: "reminder, r", - Usage: "set reminder (only premium users)", + Name: "reminder", + Aliases: []string{"r"}, + Usage: "set reminder (only premium users)", } app.Flags = []cli.Flag{ - cli.BoolFlag{ + &cli.BoolFlag{ Name: "header", Usage: "output with header", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "color", Usage: "colorize output", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "csv", Usage: "output in CSV format", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "debug", Usage: "output logs", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "namespace", Usage: "display parent task like namespace", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "indent", Usage: "display children task with indent", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "project-namespace", Usage: "display parent project like namespace", }, @@ -207,15 +217,15 @@ func main() { return nil } - app.Commands = []cli.Command{ + app.Commands = []*cli.Command{ { Name: "list", Aliases: []string{"l"}, Usage: "Show all tasks", Action: List, Flags: []cli.Flag{ - filterFlag, - sortPriorityFlag, + &filterFlag, + &sortPriorityFlag, }, ArgsUsage: " ", }, @@ -224,7 +234,7 @@ func main() { Usage: "Show task detail", Action: Show, Flags: []cli.Flag{ - browseFlag, + &browseFlag, }, ArgsUsage: "", }, @@ -234,7 +244,7 @@ func main() { Usage: "Show all completed tasks (only premium user)", Action: CompletedList, Flags: []cli.Flag{ - filterFlag, + &filterFlag, }, ArgsUsage: " ", }, @@ -244,12 +254,12 @@ func main() { Usage: "Add task", Action: Add, Flags: []cli.Flag{ - priorityFlag, - labelNamesFlag, - projectIDFlag, - projectNameFlag, - dateFlag, - reminderFlg, + &priorityFlag, + &labelNamesFlag, + &projectIDFlag, + &projectNameFlag, + &dateFlag, + &reminderFlg, }, ArgsUsage: "", }, @@ -259,12 +269,12 @@ func main() { Usage: "Modify task", Action: Modify, Flags: []cli.Flag{ - contentFlag, - priorityFlag, - labelNamesFlag, - projectIDFlag, - projectNameFlag, - dateFlag, + &contentFlag, + &priorityFlag, + &labelNamesFlag, + &projectIDFlag, + &projectNameFlag, + &dateFlag, }, ArgsUsage: "", }, @@ -300,11 +310,11 @@ func main() { Usage: "Add new project", Action: AddProject, Flags: []cli.Flag{ - cli.IntFlag{ + &cli.IntFlag{ Name: "color", Usage: "In range 30-49", }, - cli.IntFlag{ + &cli.IntFlag{ Name: "item-order", Usage: "Order index", }, diff --git a/modify.go b/modify.go index efeb4c6..2de7cad 100644 --- a/modify.go +++ b/modify.go @@ -4,7 +4,7 @@ import ( "context" "strings" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func Modify(c *cli.Context) error { diff --git a/projects.go b/projects.go index 075883e..ada60ef 100644 --- a/projects.go +++ b/projects.go @@ -1,8 +1,8 @@ package main import ( - "github.com/sachaos/todoist/lib" - "github.com/urfave/cli" + todoist "github.com/sachaos/todoist/lib" + "github.com/urfave/cli/v2" ) func traverseProjects(pjt *todoist.Project, f func(pjt *todoist.Project, depth int), depth int) { @@ -36,7 +36,7 @@ func Projects(c *cli.Context) error { defer writer.Flush() - if c.GlobalBool("header") { + if c.Bool("header") { writer.Write([]string{"ID", "Name"}) } diff --git a/quick.go b/quick.go index 8cb0faa..0a9abbb 100644 --- a/quick.go +++ b/quick.go @@ -3,7 +3,7 @@ package main import ( "context" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func Quick(c *cli.Context) error { diff --git a/show.go b/show.go index 4491644..0f06a67 100644 --- a/show.go +++ b/show.go @@ -4,8 +4,8 @@ import ( "strings" "github.com/pkg/browser" - "github.com/sachaos/todoist/lib" - "github.com/urfave/cli" + todoist "github.com/sachaos/todoist/lib" + "github.com/urfave/cli/v2" ) func Show(c *cli.Context) error { diff --git a/sync.go b/sync.go index 88653db..7488fc5 100644 --- a/sync.go +++ b/sync.go @@ -3,7 +3,7 @@ package main import ( "context" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func Sync(c *cli.Context) error { From 440c9fcbafc577546e68e5ad6213701a8a370436 Mon Sep 17 00:00:00 2001 From: HacDan Date: Mon, 10 Apr 2023 00:02:34 -0400 Subject: [PATCH 2/4] style(main.go): corrected package import rename to keep the codebase clean Tooling is auto-adding package name to the library. --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 119d7d7..a729dc6 100644 --- a/main.go +++ b/main.go @@ -13,7 +13,7 @@ import ( "github.com/fatih/color" "github.com/rkoesters/xdg/basedir" - todoist "github.com/sachaos/todoist/lib" + x"github.com/sachaos/todoist/lib" "github.com/spf13/viper" "github.com/urfave/cli/v2" ) From 9be2df4630653bb37a673599101d59e7e7c41fb0 Mon Sep 17 00:00:00 2001 From: HacDan Date: Mon, 10 Apr 2023 20:40:22 -0400 Subject: [PATCH 3/4] Revert "style(main.go): corrected package import rename to keep the codebase clean" This reverts commit 440c9fcbafc577546e68e5ad6213701a8a370436. --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index a729dc6..119d7d7 100644 --- a/main.go +++ b/main.go @@ -13,7 +13,7 @@ import ( "github.com/fatih/color" "github.com/rkoesters/xdg/basedir" - x"github.com/sachaos/todoist/lib" + todoist "github.com/sachaos/todoist/lib" "github.com/spf13/viper" "github.com/urfave/cli/v2" ) From dc5ccba99faa2c4cdf5b933b3ab4d9026e0337bd Mon Sep 17 00:00:00 2001 From: HacDan Date: Mon, 10 Apr 2023 20:41:19 -0400 Subject: [PATCH 4/4] style(main.go) corrected package import rename to keep the codebase clean. Tooling is auto-adding package name to the library. --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 119d7d7..21ecb56 100644 --- a/main.go +++ b/main.go @@ -13,7 +13,7 @@ import ( "github.com/fatih/color" "github.com/rkoesters/xdg/basedir" - todoist "github.com/sachaos/todoist/lib" + "github.com/sachaos/todoist/lib" "github.com/spf13/viper" "github.com/urfave/cli/v2" )