Commit
+51 -3 +/-1 browse
1 | diff --git a/pkg/cmd/cmd.go b/pkg/cmd/cmd.go |
2 | index 2c8fdc9..8540c48 100644 |
3 | --- a/pkg/cmd/cmd.go |
4 | +++ b/pkg/cmd/cmd.go |
5 | @@ -8,6 +8,8 @@ import ( |
6 | "os/user" |
7 | "path" |
8 | "sort" |
9 | + "strconv" |
10 | + "strings" |
11 | "time" |
12 | |
13 | cli "github.com/jawher/mow.cli" |
14 | @@ -28,6 +30,26 @@ func defaultConfigPath() string { |
15 | return path.Join(u.HomeDir, "/.pomo/config.json") |
16 | } |
17 | |
18 | + func parseRange(arg string) (int, int, error) { |
19 | + if strings.Contains(arg, ":") { |
20 | + split := strings.Split(arg, ":") |
21 | + start, err := strconv.ParseInt(split[0], 0, 64) |
22 | + if err != nil { |
23 | + return -1, -1, err |
24 | + } |
25 | + end, err := strconv.ParseInt(split[1], 0, 64) |
26 | + if err != nil { |
27 | + return -1, -1, err |
28 | + } |
29 | + return int(start), int(end), nil |
30 | + } |
31 | + n, err := strconv.ParseInt(arg, 0, 64) |
32 | + if err != nil { |
33 | + return -1, -1, err |
34 | + } |
35 | + return int(n), int(n), err |
36 | + } |
37 | + |
38 | func start(config *pomo.Config) func(*cli.Cmd) { |
39 | return func(cmd *cli.Cmd) { |
40 | cmd.Spec = "[OPTIONS] MESSAGE" |
41 | @@ -193,14 +215,40 @@ func list(config *pomo.Config) func(*cli.Cmd) { |
42 | |
43 | func _delete(config *pomo.Config) func(*cli.Cmd) { |
44 | return func(cmd *cli.Cmd) { |
45 | - cmd.Spec = "[OPTIONS] TASK_ID" |
46 | - var taskID = cmd.IntArg("TASK_ID", -1, "task to delete") |
47 | + cmd.Spec = "[OPTIONS] [TASK_ID...]" |
48 | + cmd.LongDesc = ` |
49 | + delete one or more tasks by ID |
50 | + |
51 | + ## Examples: |
52 | + # delete a single task |
53 | + pomo delete 1 |
54 | + # delete a range of tasks (1 - 10) |
55 | + pomo delete 1:10 |
56 | + # delete multiple tasks 5, 10, and 20 |
57 | + pomo delete 5 10 20 |
58 | + ` |
59 | + var taskIDs = cmd.StringsArg("TASK_ID", nil, "task to delete") |
60 | cmd.Action = func() { |
61 | + |
62 | db, err := pomo.NewStore(config.DBPath) |
63 | maybe(err) |
64 | defer db.Close() |
65 | maybe(db.With(func(tx *sql.Tx) error { |
66 | - return db.DeleteTask(tx, *taskID) |
67 | + for _, expr := range *taskIDs { |
68 | + start, end, err := parseRange(expr) |
69 | + if err != nil { |
70 | + return err |
71 | + } |
72 | + for i := start; i <= end; i++ { |
73 | + err := db.DeleteTask(tx, i) |
74 | + if err != nil { |
75 | + return err |
76 | + } |
77 | + fmt.Printf("deleted task %d\n", i) |
78 | + } |
79 | + } |
80 | + |
81 | + return nil |
82 | })) |
83 | } |
84 | } |