Skip to content

Commit

Permalink
confirm when deleting labels
Browse files Browse the repository at this point in the history
  • Loading branch information
kobtea committed Sep 17, 2018
1 parent 9e57400 commit 942eddb
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions cmd/todoist/cmd/label.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package cmd

import (
"fmt"

"bufio"
"context"
"errors"
"fmt"
"github.com/kobtea/go-todoist/cmd/util"
"github.com/kobtea/go-todoist/todoist"
"github.com/spf13/cobra"
"os"
"strconv"
"strings"
)
Expand Down Expand Up @@ -138,6 +139,23 @@ var labelDeleteCmd = &cobra.Command{
return util.ProcessIDs(
args,
func(ids []todoist.ID) error {
var labels []todoist.Label
for _, id := range ids {
label := client.Label.Resolve(id)
if label == nil {
return fmt.Errorf("invalid id: %s", id)
}
labels = append(labels, *label)
}
fmt.Println(util.LabelTableString(labels))

reader := bufio.NewReader(os.Stdin)
fmt.Print("are you sure to delete above label(s)? (y/[n]): ")
ans, err := reader.ReadString('\n')
if ans != "y\n" || err != nil {
fmt.Println("abort")
return errors.New("abort")
}
for _, id := range ids {
if err := client.Label.Delete(id); err != nil {
return err
Expand All @@ -146,6 +164,9 @@ var labelDeleteCmd = &cobra.Command{
return nil
})
}); err != nil {
if err.Error() == "abort" {
return nil
}
return err
}
fmt.Println("Successful deleting of label(s).")
Expand Down

0 comments on commit 942eddb

Please sign in to comment.