Skip to content

Commit

Permalink
📝 some fixes and added tasklist title update
Browse files Browse the repository at this point in the history
  • Loading branch information
BRO3886 committed Nov 15, 2020
1 parent dee4df0 commit d704f06
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- [x] Login
- [x] View Task-List
- [x] Create Task-List
- [ ] Update Task-List title
- [x] Update Task-List title
- [x] Delete Task-List
- [x] View Tasks
- [x] Create Tasks
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var cfgFile string
var rootCmd = &cobra.Command{
Use: "gtasks",
Short: "A CLI Tool for Google Tasks",
Version: "0.8.0",
Version: "0.9.0",
Long: `A CLI Tool for managing your Google Tasks:
Made with ♥ by https://github.com/BRO3886
Expand Down
53 changes: 51 additions & 2 deletions cmd/tasklists.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ var createlistsCmd = &cobra.Command{
if err != nil {
log.Fatalf("Unable to create task list. %v", err)
}
fmt.Println("Created: " + r.Title)
title = ""
fmt.Println(color.GreenString("Created: ") + r.Title)
},
}

Expand Down Expand Up @@ -132,10 +133,58 @@ var removeListCmd = &cobra.Command{
},
}

var updateTitleCmd = &cobra.Command{
Use: "update",
Short: "update tasklist title",
Long: `Update tasklist title for the currently signed in account`,
Run: func(cmd *cobra.Command, args []string) {
config := utils.ReadCredentials()
client := getClient(config)
srv, err := tasks.New(client)
if err != nil {
log.Fatalf("Unable to retrieve tasks Client %v", err)
}
if title == "" {
fmt.Println("Title should not be empty. Use -t for title.\nExamples:\ngtasks tasklists create -t <TITLE>\ngtasks tasklists create --title <TITLE>")
return
}

list, err := utils.GetTaskLists(srv)
if err != nil {
log.Fatalf("Error %v", err)
}

fmt.Println("Choose a Tasklist:")
var l []string
for _, i := range list {
l = append(l, i.Title)
}

prompt := promptui.Select{
Label: "Select Tasklist",
Items: l,
}
option, _, err := prompt.Run()
if err != nil {
color.Red("Error: " + err.Error())
return
}
t := list[option]
t.Title = title
t, err = utils.UpdateTaskList(srv, t)
if err != nil {
color.Red("Error updating tasklist: " + err.Error())
return
}
color.Green("Tasklist title updated")
},
}

var title string

func init() {
createlistsCmd.Flags().StringVarP(&title, "title", "t", "", "title of task list (required)")
tasklistsCmd.AddCommand(showlistsCmd, createlistsCmd, removeListCmd)
updateTitleCmd.Flags().StringVarP(&title, "title", "t", "", "title of task list (required)")
tasklistsCmd.AddCommand(showlistsCmd, createlistsCmd, removeListCmd, updateTitleCmd)
rootCmd.AddCommand(tasklistsCmd)
}

0 comments on commit d704f06

Please sign in to comment.