diff --git a/main.go b/main.go index 971e7d5..f8a6891 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,8 @@ import ( "os" "sort" "time" + + cli "github.com/jawher/mow.cli" ) func start(path *string) func(*cli.Cmd) { @@ -67,6 +69,37 @@ func create(path *string) func(*cli.Cmd) { } } +func begin(path *string) func(*cli.Cmd) { + return func(cmd *cli.Cmd) { + cmd.Spec = "ID" + var jobId = cmd.IntArg("ID", -1, "ID of Pomodoro to begin") + + cmd.Action = func() { + db, err := NewStore(*path) + maybe(err) + defer db.Close() + tasks, err := db.ReadTasks() + maybe(err) + task := &Task{} + for _, task = range tasks { + if task.ID == *jobId { + break + } + } + if task.ID == *jobId { + runner, err := NewTaskRunner(task, db, NewXnotifier(*path+"/icon.png")) + maybe(err) + server, err := NewServer(*path+"/pomo.sock", runner) + maybe(err) + server.Start() + defer server.Stop() + runner.Start() + startUI(runner) + } + } + } +} + func initialize(path *string) func(*cli.Cmd) { return func(cmd *cli.Cmd) { cmd.Spec = "[OPTIONS]" @@ -157,6 +190,7 @@ func main() { app.Command("start s", "start a new task", start(path)) app.Command("init", "initialize the sqlite database", initialize(path)) app.Command("create c", "create a new task without starting", create(path)) + app.Command("begin b", "begin requested pomodoro", begin(path)) app.Command("list l", "list historical tasks", list(path)) app.Command("delete d", "delete a stored task", _delete(path)) app.Command("status st", "output the current status", _status(path))