2018-01-16 10:50:08 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-01-16 13:02:35 +01:00
|
|
|
"encoding/json"
|
2018-01-16 10:50:08 +01:00
|
|
|
"github.com/jawher/mow.cli"
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2018-01-17 08:44:25 +01:00
|
|
|
func start(path *string) func(*cli.Cmd) {
|
|
|
|
return func(cmd *cli.Cmd) {
|
|
|
|
cmd.Spec = "[OPTIONS] MESSAGE"
|
|
|
|
var (
|
2018-01-20 13:17:58 +01:00
|
|
|
duration = cmd.StringOpt("d duration", "25m", "duration of each stent")
|
|
|
|
pomodoros = cmd.IntOpt("p pomodoros", 4, "number of pomodoros")
|
|
|
|
message = cmd.StringArg("MESSAGE", "", "descriptive name of the given task")
|
|
|
|
tags = cmd.StringsOpt("t tag", []string{}, "tags associated with this task")
|
2018-01-17 08:44:25 +01:00
|
|
|
)
|
|
|
|
cmd.Action = func() {
|
|
|
|
parsed, err := time.ParseDuration(*duration)
|
|
|
|
maybe(err)
|
|
|
|
db, err := NewStore(*path)
|
|
|
|
maybe(err)
|
|
|
|
defer db.Close()
|
|
|
|
task := Task{
|
2018-01-20 13:17:58 +01:00
|
|
|
Message: *message,
|
|
|
|
Tags: *tags,
|
|
|
|
pomodoros: *pomodoros,
|
|
|
|
duration: parsed,
|
2018-01-17 08:44:25 +01:00
|
|
|
}
|
2018-01-20 13:03:23 +01:00
|
|
|
run(task, &I3{}, db)
|
2018-01-16 10:50:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-17 08:44:25 +01:00
|
|
|
func initialize(path *string) func(*cli.Cmd) {
|
|
|
|
return func(cmd *cli.Cmd) {
|
|
|
|
cmd.Spec = "[OPTIONS]"
|
|
|
|
cmd.Action = func() {
|
|
|
|
db, err := NewStore(*path)
|
|
|
|
maybe(err)
|
|
|
|
defer db.Close()
|
|
|
|
maybe(initDB(db))
|
|
|
|
}
|
2018-01-16 12:06:20 +01:00
|
|
|
}
|
|
|
|
}
|
2018-01-16 10:50:08 +01:00
|
|
|
|
2018-01-17 08:44:25 +01:00
|
|
|
func list(path *string) func(*cli.Cmd) {
|
|
|
|
return func(cmd *cli.Cmd) {
|
2018-01-20 17:51:27 +01:00
|
|
|
cmd.Spec = "[OPTIONS]"
|
|
|
|
var asJSON = cmd.BoolOpt("json", false, "output task history as JSON")
|
2018-01-17 08:44:25 +01:00
|
|
|
cmd.Action = func() {
|
|
|
|
db, err := NewStore(*path)
|
|
|
|
maybe(err)
|
|
|
|
defer db.Close()
|
|
|
|
tasks, err := db.ReadTasks()
|
|
|
|
maybe(err)
|
2018-01-20 17:51:27 +01:00
|
|
|
if *asJSON {
|
|
|
|
maybe(json.NewEncoder(os.Stdout).Encode(tasks))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
config, _ := NewConfig(*path + "/config.json")
|
|
|
|
summerizeTasks(config, tasks)
|
2018-01-17 08:44:25 +01:00
|
|
|
}
|
2018-01-16 13:02:35 +01:00
|
|
|
}
|
|
|
|
}
|
2018-01-16 10:50:08 +01:00
|
|
|
|
2018-01-17 08:44:25 +01:00
|
|
|
func _delete(path *string) func(*cli.Cmd) {
|
2018-01-17 08:53:45 +01:00
|
|
|
return func(cmd *cli.Cmd) {
|
|
|
|
cmd.Spec = "[OPTIONS] TASK_ID"
|
|
|
|
var taskID = cmd.IntArg("TASK_ID", -1, "task to delete")
|
|
|
|
cmd.Action = func() {
|
|
|
|
db, err := NewStore(*path)
|
|
|
|
maybe(err)
|
|
|
|
defer db.Close()
|
|
|
|
maybe(db.DeleteTask(*taskID))
|
|
|
|
}
|
|
|
|
}
|
2018-01-17 08:44:25 +01:00
|
|
|
}
|
|
|
|
|
2018-01-16 10:50:08 +01:00
|
|
|
func main() {
|
|
|
|
app := cli.App("pomo", "Pomodoro CLI")
|
|
|
|
app.Spec = "[OPTIONS]"
|
2018-01-17 08:44:25 +01:00
|
|
|
var (
|
2018-01-20 17:51:27 +01:00
|
|
|
path = app.StringOpt("p path", defaultConfigPath(), "path to the pomo config directory")
|
2018-01-17 08:44:25 +01:00
|
|
|
)
|
|
|
|
app.Command("start s", "start a new task", start(path))
|
|
|
|
app.Command("init", "initialize the sqlite database", initialize(path))
|
|
|
|
app.Command("list l", "list historical tasks", list(path))
|
|
|
|
app.Command("delete d", "delete a stored task", _delete(path))
|
2018-01-16 10:50:08 +01:00
|
|
|
app.Run(os.Args)
|
|
|
|
}
|