Commit
+28 -2 +/-1 browse
1 | diff --git a/main.go b/main.go |
2 | index 1e5d896..939caf5 100644 |
3 | --- a/main.go |
4 | +++ b/main.go |
5 | @@ -5,8 +5,6 @@ import ( |
6 | "os" |
7 | "sort" |
8 | "time" |
9 | - |
10 | - "github.com/jawher/mow.cli" |
11 | ) |
12 | |
13 | func start(path *string) func(*cli.Cmd) { |
14 | @@ -42,6 +40,33 @@ func start(path *string) func(*cli.Cmd) { |
15 | } |
16 | } |
17 | |
18 | + func create(path *string) func(*cli.Cmd) { |
19 | + return func(cmd *cli.Cmd) { |
20 | + cmd.Spec = "[OPTIONS] MESSAGE" |
21 | + var ( |
22 | + duration = cmd.StringOpt("d duration", "25m", "duration of each stent") |
23 | + pomodoros = cmd.IntOpt("p pomodoros", 4, "number of pomodoros") |
24 | + message = cmd.StringArg("MESSAGE", "", "descriptive name of the given task") |
25 | + tags = cmd.StringsOpt("t tag", []string{}, "tags associated with this task") |
26 | + ) |
27 | + cmd.Action = func() { |
28 | + parsed, err := time.ParseDuration(*duration) |
29 | + maybe(err) |
30 | + db, err := NewStore(*path) |
31 | + maybe(err) |
32 | + defer db.Close() |
33 | + task := &Task{ |
34 | + Message: *message, |
35 | + Tags: *tags, |
36 | + NPomodoros: *pomodoros, |
37 | + Duration: parsed, |
38 | + } |
39 | + taskID, err := db.CreateTask(*task) |
40 | + maybe(err) |
41 | + } |
42 | + } |
43 | + } |
44 | + |
45 | func initialize(path *string) func(*cli.Cmd) { |
46 | return func(cmd *cli.Cmd) { |
47 | cmd.Spec = "[OPTIONS]" |
48 | @@ -131,6 +156,7 @@ func main() { |
49 | app.Version("v version", Version) |
50 | app.Command("start s", "start a new task", start(path)) |
51 | app.Command("init", "initialize the sqlite database", initialize(path)) |
52 | + app.Command("create c", "create a new task without starting", start(path)) |
53 | app.Command("list l", "list historical tasks", list(path)) |
54 | app.Command("delete d", "delete a stored task", _delete(path)) |
55 | app.Command("status st", "output the current status", _status(path)) |