Skip to content

Commit

Permalink
⬆️ moved to NewService method since tasks.New() was deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
BRO3886 committed Jun 18, 2021
1 parent cdf6ed2 commit 66360ed
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
16 changes: 11 additions & 5 deletions cmd/tasklists.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"context"
"errors"
"fmt"
"log"
Expand All @@ -9,6 +10,7 @@ import (
"github.com/fatih/color"
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
"google.golang.org/api/option"
"google.golang.org/api/tasks/v1"
)

Expand Down Expand Up @@ -47,7 +49,8 @@ var showlistsCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
config := internal.ReadCredentials()
client := getClient(config)
srv, err := tasks.New(client)

srv, err := tasks.NewService(context.Background(), option.WithHTTPClient(client))
if err != nil {
log.Fatalf("Unable to retrieve tasks Client %v", err)
}
Expand All @@ -71,7 +74,8 @@ var createlistsCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
config := internal.ReadCredentials()
client := getClient(config)
srv, err := tasks.New(client)

srv, err := tasks.NewService(context.Background(), option.WithHTTPClient(client))
if err != nil {
log.Fatalf("Unable to retrieve tasks Client %v", err)
}
Expand All @@ -97,7 +101,7 @@ var removeListCmd = &cobra.Command{
config := internal.ReadCredentials()
client := getClient(config)

srv, err := tasks.New(client)
srv, err := tasks.NewService(context.Background(), option.WithHTTPClient(client))
if err != nil {
log.Fatalf("Unable to retrieve tasks Client %v", err)
}
Expand Down Expand Up @@ -140,7 +144,8 @@ var updateTitleCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
config := internal.ReadCredentials()
client := getClient(config)
srv, err := tasks.New(client)

srv, err := tasks.NewService(context.Background(), option.WithHTTPClient(client))
if err != nil {
log.Fatalf("Unable to retrieve tasks Client %v", err)
}
Expand Down Expand Up @@ -171,7 +176,8 @@ var updateTitleCmd = &cobra.Command{
}
t := list[option]
t.Title = title
t, err = internal.UpdateTaskList(srv, t)

_, err = internal.UpdateTaskList(srv, t)
if err != nil {
color.Red("Error updating tasklist: " + err.Error())
return
Expand Down
21 changes: 14 additions & 7 deletions cmd/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"bufio"
"context"
"fmt"
"log"
"os"
Expand All @@ -14,6 +15,7 @@ import (
"github.com/fatih/color"
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
"google.golang.org/api/option"
"google.golang.org/api/tasks/v1"
)

Expand All @@ -38,7 +40,7 @@ var viewTasksCmd = &cobra.Command{
config := internal.ReadCredentials()
client := getClient(config)

srv, err := tasks.New(client)
srv, err := tasks.NewService(context.Background(), option.WithHTTPClient(client))
if err != nil {
log.Fatalf("Unable to retrieve tasks Client %v", err)
}
Expand Down Expand Up @@ -96,7 +98,7 @@ var createTaskCmd = &cobra.Command{
config := internal.ReadCredentials()
client := getClient(config)

srv, err := tasks.New(client)
srv, err := tasks.NewService(context.Background(), option.WithHTTPClient(client))
if err != nil {
log.Fatalf("Unable to retrieve tasks Client %v", err)
}
Expand Down Expand Up @@ -155,7 +157,7 @@ var createTaskCmd = &cobra.Command{
}
task := &tasks.Task{Title: title, Notes: notes, Due: dateString}

task, err = internal.CreateTask(srv, task, list[option].Id)
_, err = internal.CreateTask(srv, task, list[option].Id)
if err != nil {
color.Red("Unable to create task: %v", err)
return
Expand All @@ -175,7 +177,7 @@ var markCompletedCmd = &cobra.Command{
config := internal.ReadCredentials()
client := getClient(config)

srv, err := tasks.New(client)
srv, err := tasks.NewService(context.Background(), option.WithHTTPClient(client))
if err != nil {
log.Fatalf("Unable to retrieve tasks Client %v", err)
}
Expand Down Expand Up @@ -218,13 +220,15 @@ var markCompletedCmd = &cobra.Command{
Label: "Select Task",
Items: tString,
}
option, result, err = prompt.Run()

option, _, err = prompt.Run()
if err != nil {
color.Red("Error: " + err.Error())
return
}
t := tasks[option]
t.Status = "completed"

_, err = internal.UpdateTask(srv, t, tID)
if err != nil {
color.Red("Unable to mark task as completed: %v", err)
Expand All @@ -245,7 +249,7 @@ var deleteTaskCmd = &cobra.Command{
config := internal.ReadCredentials()
client := getClient(config)

srv, err := tasks.New(client)
srv, err := tasks.NewService(context.Background(), option.WithHTTPClient(client))
if err != nil {
log.Fatalf("Unable to retrieve tasks Client %v", err)
}
Expand Down Expand Up @@ -288,13 +292,16 @@ var deleteTaskCmd = &cobra.Command{
Label: "Select Task",
Items: tString,
}
option, result, err = prompt.Run()

option, _, err = prompt.Run()
if err != nil {
color.Red("Error: " + err.Error())
return
}

t := tasks[option]
t.Status = "completed"

err = internal.DeleteTask(srv, t.Id, tID)
if err != nil {
color.Red("Unable to delete task: %v", err)
Expand Down
3 changes: 3 additions & 0 deletions internal/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ func ReadCredentials() *oauth2.Config {
return config
}




func GenerateConfig() {
credString := `
{
Expand Down
2 changes: 1 addition & 1 deletion internal/tasklists.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func GetTaskLists(srv *tasks.Service) ([]*tasks.TaskList, error) {
}

if len(r.Items) == 0 {
return nil, errors.New("No Tasklist found")
return nil, errors.New("no Tasklist found")
}
return r.Items, nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func GetTasks(srv *tasks.Service, id string, showCompleted bool) ([]*tasks.Task,
log.Fatalf("Unable to retrieve tasks. %v", err)
}
if len(r.Items) == 0 {
return nil, errors.New("No Tasks found")
return nil, errors.New("no Tasks found")
}
return r.Items, nil
}
Expand Down

0 comments on commit 66360ed

Please sign in to comment.