Skip to content

Commit

Permalink
confirm when deleting filters
Browse files Browse the repository at this point in the history
  • Loading branch information
kobtea committed Sep 15, 2018
1 parent 0e843fd commit 9e57400
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions cmd/todoist/cmd/filter.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 @@ -149,6 +150,23 @@ var filterDeleteCmd = &cobra.Command{
return util.ProcessIDs(
args,
func(ids []todoist.ID) error {
var filters []todoist.Filter
for _, id := range ids {
filter := client.Filter.Resolve(id)
if filter == nil {
return fmt.Errorf("invalid id: %s", id)
}
filters = append(filters, *filter)
}
fmt.Println(util.FilterTableString(filters))

reader := bufio.NewReader(os.Stdin)
fmt.Print("are you sure to delete above filter(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.Filter.Delete(id); err != nil {
return err
Expand All @@ -157,6 +175,9 @@ var filterDeleteCmd = &cobra.Command{
return nil
})
}); err != nil {
if err.Error() == "abort" {
return nil
}
return err
}
fmt.Println("Successful deleting of filter(s).")
Expand Down

0 comments on commit 9e57400

Please sign in to comment.