github.com/zaquestion/lab@v0.25.1/cmd/todo_done.go (about) 1 package cmd 2 3 import ( 4 "fmt" 5 "github.com/MakeNowJust/heredoc/v2" 6 "strconv" 7 8 "github.com/spf13/cobra" 9 lab "github.com/zaquestion/lab/internal/gitlab" 10 ) 11 12 var ( 13 all bool 14 ) 15 16 var todoDoneCmd = &cobra.Command{ 17 Use: "done", 18 Short: "Mark todo list entry as Done", 19 Example: heredoc.Doc(` 20 lab todo done 21 lab todo done -a 22 lab todo done -n 10 23 lab todo done -p 24 lab todo done -t mr`), 25 PersistentPreRun: labPersistentPreRun, 26 Run: func(cmd *cobra.Command, args []string) { 27 if all { 28 err := lab.TodoMarkAllDone() 29 if err != nil { 30 log.Fatal(err) 31 } 32 fmt.Println("All Todo entries marked as Done") 33 return 34 } 35 if len(args) == 0 { 36 log.Fatalf("Specify todo id to be marked as done") 37 } 38 toDoNum, err := strconv.Atoi(args[0]) 39 if err != nil { 40 log.Fatal(err) 41 } 42 err = lab.TodoMarkDone(toDoNum) 43 if err != nil { 44 log.Fatal(err) 45 } 46 fmt.Println(toDoNum, "marked as Done") 47 }, 48 } 49 50 func init() { 51 todoDoneCmd.Flags().BoolVarP(&all, "all", "a", false, "mark all Todos as Done") 52 todoCmd.AddCommand(todoDoneCmd) 53 }