|
|
|
@ -1,17 +1,34 @@
|
|
|
|
|
package main
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"database/sql"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
"os/user"
|
|
|
|
|
"path"
|
|
|
|
|
"sort"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
cli "github.com/jawher/mow.cli"
|
|
|
|
|
|
|
|
|
|
pomo "github.com/kevinschoon/pomo/pkg/internal"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func start(config *Config) func(*cli.Cmd) {
|
|
|
|
|
func maybe(err error) {
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Printf("Error:\n%s\n", err)
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func defaultConfigPath() string {
|
|
|
|
|
u, err := user.Current()
|
|
|
|
|
maybe(err)
|
|
|
|
|
return path.Join(u.HomeDir, "/.pomo/config.json")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func start(config *pomo.Config) func(*cli.Cmd) {
|
|
|
|
|
return func(cmd *cli.Cmd) {
|
|
|
|
|
cmd.Spec = "[OPTIONS] MESSAGE"
|
|
|
|
|
var (
|
|
|
|
@ -23,10 +40,10 @@ func start(config *Config) func(*cli.Cmd) {
|
|
|
|
|
cmd.Action = func() {
|
|
|
|
|
parsed, err := time.ParseDuration(*duration)
|
|
|
|
|
maybe(err)
|
|
|
|
|
db, err := NewStore(config.DBPath)
|
|
|
|
|
db, err := pomo.NewStore(config.DBPath)
|
|
|
|
|
maybe(err)
|
|
|
|
|
defer db.Close()
|
|
|
|
|
task := &Task{
|
|
|
|
|
task := &pomo.Task{
|
|
|
|
|
Message: *message,
|
|
|
|
|
Tags: *tags,
|
|
|
|
|
NPomodoros: *pomodoros,
|
|
|
|
@ -40,19 +57,19 @@ func start(config *Config) func(*cli.Cmd) {
|
|
|
|
|
task.ID = id
|
|
|
|
|
return nil
|
|
|
|
|
}))
|
|
|
|
|
runner, err := NewTaskRunner(task, config)
|
|
|
|
|
runner, err := pomo.NewTaskRunner(task, config)
|
|
|
|
|
maybe(err)
|
|
|
|
|
server, err := NewServer(runner, config)
|
|
|
|
|
server, err := pomo.NewServer(runner, config)
|
|
|
|
|
maybe(err)
|
|
|
|
|
server.Start()
|
|
|
|
|
defer server.Stop()
|
|
|
|
|
runner.Start()
|
|
|
|
|
startUI(runner)
|
|
|
|
|
pomo.StartUI(runner)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func create(config *Config) func(*cli.Cmd) {
|
|
|
|
|
func create(config *pomo.Config) func(*cli.Cmd) {
|
|
|
|
|
return func(cmd *cli.Cmd) {
|
|
|
|
|
cmd.Spec = "[OPTIONS] MESSAGE"
|
|
|
|
|
var (
|
|
|
|
@ -64,10 +81,10 @@ func create(config *Config) func(*cli.Cmd) {
|
|
|
|
|
cmd.Action = func() {
|
|
|
|
|
parsed, err := time.ParseDuration(*duration)
|
|
|
|
|
maybe(err)
|
|
|
|
|
db, err := NewStore(config.DBPath)
|
|
|
|
|
db, err := pomo.NewStore(config.DBPath)
|
|
|
|
|
maybe(err)
|
|
|
|
|
defer db.Close()
|
|
|
|
|
task := &Task{
|
|
|
|
|
task := &pomo.Task{
|
|
|
|
|
Message: *message,
|
|
|
|
|
Tags: *tags,
|
|
|
|
|
NPomodoros: *pomodoros,
|
|
|
|
@ -85,7 +102,7 @@ func create(config *Config) func(*cli.Cmd) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func begin(config *Config) func(*cli.Cmd) {
|
|
|
|
|
func begin(config *pomo.Config) func(*cli.Cmd) {
|
|
|
|
|
return func(cmd *cli.Cmd) {
|
|
|
|
|
cmd.Spec = "[OPTIONS] TASK_ID"
|
|
|
|
|
var (
|
|
|
|
@ -93,10 +110,10 @@ func begin(config *Config) func(*cli.Cmd) {
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
cmd.Action = func() {
|
|
|
|
|
db, err := NewStore(config.DBPath)
|
|
|
|
|
db, err := pomo.NewStore(config.DBPath)
|
|
|
|
|
maybe(err)
|
|
|
|
|
defer db.Close()
|
|
|
|
|
var task *Task
|
|
|
|
|
var task *pomo.Task
|
|
|
|
|
maybe(db.With(func(tx *sql.Tx) error {
|
|
|
|
|
read, err := db.ReadTask(tx, *taskId)
|
|
|
|
|
if err != nil {
|
|
|
|
@ -107,34 +124,34 @@ func begin(config *Config) func(*cli.Cmd) {
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
task.Pomodoros = []*Pomodoro{}
|
|
|
|
|
task.Pomodoros = []*pomo.Pomodoro{}
|
|
|
|
|
return nil
|
|
|
|
|
}))
|
|
|
|
|
runner, err := NewTaskRunner(task, config)
|
|
|
|
|
runner, err := pomo.NewTaskRunner(task, config)
|
|
|
|
|
maybe(err)
|
|
|
|
|
server, err := NewServer(runner, config)
|
|
|
|
|
server, err := pomo.NewServer(runner, config)
|
|
|
|
|
maybe(err)
|
|
|
|
|
server.Start()
|
|
|
|
|
defer server.Stop()
|
|
|
|
|
runner.Start()
|
|
|
|
|
startUI(runner)
|
|
|
|
|
pomo.StartUI(runner)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func initialize(config *Config) func(*cli.Cmd) {
|
|
|
|
|
func initialize(config *pomo.Config) func(*cli.Cmd) {
|
|
|
|
|
return func(cmd *cli.Cmd) {
|
|
|
|
|
cmd.Spec = "[OPTIONS]"
|
|
|
|
|
cmd.Action = func() {
|
|
|
|
|
db, err := NewStore(config.DBPath)
|
|
|
|
|
db, err := pomo.NewStore(config.DBPath)
|
|
|
|
|
maybe(err)
|
|
|
|
|
defer db.Close()
|
|
|
|
|
maybe(initDB(db))
|
|
|
|
|
maybe(pomo.InitDB(db))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func list(config *Config) func(*cli.Cmd) {
|
|
|
|
|
func list(config *pomo.Config) func(*cli.Cmd) {
|
|
|
|
|
return func(cmd *cli.Cmd) {
|
|
|
|
|
cmd.Spec = "[OPTIONS]"
|
|
|
|
|
var (
|
|
|
|
@ -147,17 +164,17 @@ func list(config *Config) func(*cli.Cmd) {
|
|
|
|
|
cmd.Action = func() {
|
|
|
|
|
duration, err := time.ParseDuration(*duration)
|
|
|
|
|
maybe(err)
|
|
|
|
|
db, err := NewStore(config.DBPath)
|
|
|
|
|
db, err := pomo.NewStore(config.DBPath)
|
|
|
|
|
maybe(err)
|
|
|
|
|
defer db.Close()
|
|
|
|
|
maybe(db.With(func(tx *sql.Tx) error {
|
|
|
|
|
tasks, err := db.ReadTasks(tx)
|
|
|
|
|
maybe(err)
|
|
|
|
|
if *assend {
|
|
|
|
|
sort.Sort(sort.Reverse(ByID(tasks)))
|
|
|
|
|
sort.Sort(sort.Reverse(pomo.ByID(tasks)))
|
|
|
|
|
}
|
|
|
|
|
if !*all {
|
|
|
|
|
tasks = After(time.Now().Add(-duration), tasks)
|
|
|
|
|
tasks = pomo.After(time.Now().Add(-duration), tasks)
|
|
|
|
|
}
|
|
|
|
|
if *limit > 0 && (len(tasks) > *limit) {
|
|
|
|
|
tasks = tasks[0:*limit]
|
|
|
|
@ -167,19 +184,19 @@ func list(config *Config) func(*cli.Cmd) {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
maybe(err)
|
|
|
|
|
summerizeTasks(config, tasks)
|
|
|
|
|
pomo.SummerizeTasks(config, tasks)
|
|
|
|
|
return nil
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func _delete(config *Config) func(*cli.Cmd) {
|
|
|
|
|
func _delete(config *pomo.Config) func(*cli.Cmd) {
|
|
|
|
|
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(config.DBPath)
|
|
|
|
|
db, err := pomo.NewStore(config.DBPath)
|
|
|
|
|
maybe(err)
|
|
|
|
|
defer db.Close()
|
|
|
|
|
maybe(db.With(func(tx *sql.Tx) error {
|
|
|
|
@ -189,24 +206,24 @@ func _delete(config *Config) func(*cli.Cmd) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func _status(config *Config) func(*cli.Cmd) {
|
|
|
|
|
func _status(config *pomo.Config) func(*cli.Cmd) {
|
|
|
|
|
return func(cmd *cli.Cmd) {
|
|
|
|
|
cmd.Spec = "[OPTIONS]"
|
|
|
|
|
cmd.Action = func() {
|
|
|
|
|
client, err := NewClient(config.SocketPath)
|
|
|
|
|
client, err := pomo.NewClient(config.SocketPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
outputStatus(Status{})
|
|
|
|
|
pomo.OutputStatus(pomo.Status{})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
defer client.Close()
|
|
|
|
|
status, err := client.Status()
|
|
|
|
|
maybe(err)
|
|
|
|
|
outputStatus(*status)
|
|
|
|
|
pomo.OutputStatus(*status)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func _config(config *Config) func(*cli.Cmd) {
|
|
|
|
|
func _config(config *pomo.Config) func(*cli.Cmd) {
|
|
|
|
|
return func(cmd *cli.Cmd) {
|
|
|
|
|
cmd.Spec = "[OPTIONS]"
|
|
|
|
|
cmd.Action = func() {
|
|
|
|
@ -215,18 +232,18 @@ func _config(config *Config) func(*cli.Cmd) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
func Run() {
|
|
|
|
|
app := cli.App("pomo", "Pomodoro CLI")
|
|
|
|
|
app.LongDesc = "Pomo helps you track what you did, how long it took you to do it, and how much effort you expect it to take."
|
|
|
|
|
app.Spec = "[OPTIONS]"
|
|
|
|
|
var (
|
|
|
|
|
config = &Config{}
|
|
|
|
|
config = &pomo.Config{}
|
|
|
|
|
path = app.StringOpt("p path", defaultConfigPath(), "path to the pomo config directory")
|
|
|
|
|
)
|
|
|
|
|
app.Before = func() {
|
|
|
|
|
maybe(LoadConfig(*path, config))
|
|
|
|
|
maybe(pomo.LoadConfig(*path, config))
|
|
|
|
|
}
|
|
|
|
|
app.Version("v version", Version)
|
|
|
|
|
app.Version("v version", pomo.Version)
|
|
|
|
|
app.Command("start s", "start a new task", start(config))
|
|
|
|
|
app.Command("init", "initialize the sqlite database", initialize(config))
|
|
|
|
|
app.Command("config cf", "display the current configuration", _config(config))
|