Skip to content

Commit

Permalink
feat: add flag to only show completed tasks (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Bender authored Oct 6, 2021
1 parent 5da5863 commit 1b5b867
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions cmd/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var viewTasksCmd = &cobra.Command{

utils.Print("Tasks in %s:\n", tList.Title)

tasks, err := api.GetTasks(srv, tList.Id, includeCompletedFlag)
tasks, err := api.GetTasks(srv, tList.Id, viewTasksFlags.includeCompleted || viewTasksFlags.onlyCompleted)
if err != nil {
color.Red(err.Error())
return
Expand All @@ -77,6 +77,10 @@ var viewTasksCmd = &cobra.Command{
// table.SetRowSeparator("-")

for ind, task := range tasks {
if viewTasksFlags.onlyCompleted && task.Status == "needsAction" {
continue
}

row := []string{fmt.Sprintf("%d", ind+1), task.Title, task.Notes}

if task.Status == "needsAction" {
Expand Down Expand Up @@ -221,9 +225,12 @@ var deleteTaskCmd = &cobra.Command{
}

var (
includeCompletedFlag bool
taskListFlag string
addTaskFlags struct {
viewTasksFlags struct {
includeCompleted bool
onlyCompleted bool
}
taskListFlag string
addTaskFlags struct {
title string
note string
due string
Expand All @@ -234,7 +241,8 @@ func init() {
createTaskCmd.Flags().StringVarP(&addTaskFlags.title, "title", "t", "", "use this flag to set a tasks title")
createTaskCmd.Flags().StringVarP(&addTaskFlags.note, "note", "n", "", "use this flag to set a tasks note")
createTaskCmd.Flags().StringVarP(&addTaskFlags.due, "due", "d", "", "use this flag to set a tasks due date")
viewTasksCmd.Flags().BoolVarP(&includeCompletedFlag, "include-completed", "i", false, "use this flag to include completed tasks")
viewTasksCmd.Flags().BoolVarP(&viewTasksFlags.includeCompleted, "include-completed", "i", false, "use this flag to include completed tasks")
viewTasksCmd.Flags().BoolVar(&viewTasksFlags.onlyCompleted, "completed", false, "use this flag to only show completed tasks")
tasksCmd.PersistentFlags().StringVarP(&taskListFlag, "tasklist", "l", "", "use this flag to specify a tasklist")
tasksCmd.AddCommand(viewTasksCmd, createTaskCmd, markCompletedCmd, deleteTaskCmd)
rootCmd.AddCommand(tasksCmd)
Expand Down

0 comments on commit 1b5b867

Please sign in to comment.