Skip to content

Commit

Permalink
updated output for 'com' and 'incom', changed command names to 'finis…
Browse files Browse the repository at this point in the history
…h' and 'undo'
  • Loading branch information
AndrewRoe34 committed Jul 18, 2024
1 parent 093593d commit 19eb13b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
2 changes: 1 addition & 1 deletion internal/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func NewHandler(service *service.Service) *Handler {
func (h *Handler) Execute() {
rootCmd := h.RootCmd()

rootCmd.AddCommand(h.AddCmd(), h.ModCmd(), h.GetCmd(), h.ListCmd(), h.ComCmd(), h.IncomCmd(), h.NoteCmd())
rootCmd.AddCommand(h.AddCmd(), h.ModCmd(), h.GetCmd(), h.ListCmd(), h.DoneCmd(), h.UndoCmd(), h.NoteCmd())

if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/handler/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func parseGet(args []string) ([]int, error) {
return ids, nil
}

func parseCom(args []string) ([]int, error) {
func parseDone(args []string) ([]int, error) {
var ids []int
for _, arg := range args {
id, err := strconv.Atoi(arg)
Expand Down
46 changes: 30 additions & 16 deletions internal/handler/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ func (h *Handler) ListCmd() *cobra.Command {
return listCmd
}

func (h *Handler) ComCmd() *cobra.Command {
comCmd := &cobra.Command{
Use: "com",
Short: "Complete a task by ID",
func (h *Handler) DoneCmd() *cobra.Command {
doneCmd := &cobra.Command{
Use: "done",
Short: "Marks task as complete by ID",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
ids, err := parseCom(args)
ids, err := parseDone(args)
if err != nil {
log.Fatal(err)
}
Expand All @@ -171,26 +171,40 @@ func (h *Handler) ComCmd() *cobra.Command {
if err != nil {
log.Fatal(err)
}
fmt.Printf("Completed task %d '%s'.\n", i, t.Desc)
fmt.Printf("Finished task %d '%s'.\n", i, t.Desc)
}
if len(ids) > 1 {
fmt.Printf("Finished %d tasks.\n", len(ids))
} else {
fmt.Printf("Finished 1 task.\n")
}
fmt.Printf("Completed %d tasks.\n", len(ids))
},
}
return comCmd
return doneCmd
}

func (h *Handler) IncomCmd() *cobra.Command {
incomCmd := &cobra.Command{
Use: "incom",
Short: "Incomplete a task by ID",
func (h *Handler) UndoCmd() *cobra.Command {
undoCmd := &cobra.Command{
Use: "undo",
Short: "Marks task as incomplete by ID",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Incomplete task by ID")
ids, err := parseCom(args)
ids, err := parseDone(args)
if err != nil {
log.Fatal(err)
}
fmt.Println(ids, "incomplete...")
for _, i := range ids {
t, err := h.service.GetTask(i)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Reverted task %d '%s' to incomplete.\n", i, t.Desc)
}
if len(ids) > 1 {
fmt.Printf("Reverted %d tasks.\n", len(ids))
} else {
fmt.Printf("Reverted 1 task.\n")
}
},
}
return incomCmd
return undoCmd
}

0 comments on commit 19eb13b

Please sign in to comment.