Skip to content

Commit

Permalink
todo: Implement "done" command
Browse files Browse the repository at this point in the history
The GitLab WebUI allows users to mark Todo list items as "Done".

Add a "done" command that allows users to mark Todo list items as "Done."

Signed-off-by: Prarit Bhargava <[email protected]>
  • Loading branch information
prarit committed Apr 19, 2021
1 parent efec805 commit a7f0d3f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/todo.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ var todoCmd = &cobra.Command{
todoListCmd.Run(cmd, args)
return
}
if done, _ := cmd.Flags().GetBool("done"); done {
todoDoneCmd.Run(cmd, args)
return
}

if len(args) == 0 || len(args) > 2 {
cmd.Help()
Expand Down
29 changes: 29 additions & 0 deletions cmd/todo_done.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cmd

import (
"fmt"
"log"
"strconv"

"github.com/spf13/cobra"
lab "github.com/zaquestion/lab/internal/gitlab"
)

var todoDoneCmd = &cobra.Command{
Use: "done",
Short: "Mark todo list entry as Done",
Long: ``,
PersistentPreRun: LabPersistentPreRun,
Run: func(cmd *cobra.Command, args []string) {
toDoNum, err := strconv.Atoi(args[0])
if err != nil {
log.Fatal(err)
}
lab.TodoMarkDone(toDoNum)
fmt.Println(toDoNum, "marked as Done")
},
}

func init() {
todoCmd.AddCommand(todoDoneCmd)
}
8 changes: 8 additions & 0 deletions internal/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -1709,3 +1709,11 @@ func TodoList(opts gitlab.ListTodosOptions, n int) ([]*gitlab.Todo, error) {

return list, nil
}

func TodoMarkDone(todoNum int) error {
_, err := lab.Todos.MarkTodoAsDone(todoNum)
if err != nil {
return err
}
return nil
}

0 comments on commit a7f0d3f

Please sign in to comment.