diff --git a/Gopkg.lock b/Gopkg.lock deleted file mode 100644 index 23d71b1..0000000 --- a/Gopkg.lock +++ /dev/null @@ -1,90 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[[projects]] - branch = "master" - name = "github.com/0xAX/notificator" - packages = ["."] - revision = "d81462e38c2145023f9ecf5414fc84d45d5bfe82" - -[[projects]] - name = "github.com/fatih/color" - packages = ["."] - revision = "5b77d2a35fb0ede96d138fc9a99f5c9b6aef11b4" - version = "v1.7.0" - -[[projects]] - name = "github.com/gizak/termui" - packages = ["."] - revision = "bf53c5cbea3f372f745e1d8e4660e29f73d41517" - version = "v2.3.0" - -[[projects]] - name = "github.com/jawher/mow.cli" - packages = [ - ".", - "internal/container", - "internal/flow", - "internal/fsm", - "internal/lexer", - "internal/matcher", - "internal/parser", - "internal/values" - ] - revision = "2f22195f169da29d54624afd9eb83ada5c9e4ee9" - version = "v1.0.4" - -[[projects]] - branch = "master" - name = "github.com/maruel/panicparse" - packages = ["stack"] - revision = "f20d4c4d746f810c9110e21928d4135e1f2a3efa" - -[[projects]] - name = "github.com/mattn/go-colorable" - packages = ["."] - revision = "167de6bfdfba052fa6b2d3664c8f5272e23c9072" - version = "v0.0.9" - -[[projects]] - name = "github.com/mattn/go-isatty" - packages = ["."] - revision = "6ca4dbf54d38eea1a992b3c722a76a5d1c4cb25c" - version = "v0.0.4" - -[[projects]] - name = "github.com/mattn/go-runewidth" - packages = ["."] - revision = "3ee7d812e62a0804a7d0a324e0249ca2db3476d3" - version = "v0.0.4" - -[[projects]] - name = "github.com/mattn/go-sqlite3" - packages = ["."] - revision = "c7c4067b79cc51e6dfdcef5c702e74b1e0fa7c75" - version = "v1.10.0" - -[[projects]] - name = "github.com/mitchellh/go-wordwrap" - packages = ["."] - revision = "9e67c67572bc5dd02aef930e2b0ae3c02a4b5a5c" - version = "v1.0.0" - -[[projects]] - branch = "master" - name = "github.com/nsf/termbox-go" - packages = ["."] - revision = "0938b5187e61bb8c4dcac2b0a9cf4047d83784fc" - -[[projects]] - branch = "master" - name = "golang.org/x/sys" - packages = ["unix"] - revision = "11f53e03133963fb11ae0588e08b5e0b85be8be5" - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - inputs-digest = "5913a16a0927350ebbd5117158473bb0252181f6aa8777cb5a095a18dee8bd40" - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml deleted file mode 100644 index 329330b..0000000 --- a/Gopkg.toml +++ /dev/null @@ -1,33 +0,0 @@ -# Gopkg.toml example -# -# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md -# for detailed Gopkg.toml documentation. -# -# required = ["github.com/user/thing/cmd/thing"] -# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] -# -# [[constraint]] -# name = "github.com/user/project" -# version = "1.0.0" -# -# [[constraint]] -# name = "github.com/user/project2" -# branch = "dev" -# source = "github.com/myfork/project2" -# -# [[override]] -# name = "github.com/x/y" -# version = "2.4.0" - - -[[constraint]] - name = "github.com/fatih/color" - version = "1.5.0" - -[[constraint]] - name = "github.com/jawher/mow.cli" - version = "1.0.3" - -[[constraint]] - name = "github.com/mattn/go-sqlite3" - version = "1.6.0" diff --git a/Makefile b/Makefile index 9505092..eb7a2e5 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,14 @@ DOCKER_CMD=docker run --rm -ti -w /build/pomo -v $$PWD:/build/pomo DOCKER_IMAGE=pomo-build + VERSION ?= $(shell git describe --tags 2>/dev/null) ifeq "$(VERSION)" "" VERSION := UNKNOWN endif +LDFLAGS=\ + -X github.com/kevinschoon/pomo/pkg/internal/version.Version=$(VERSION) + .PHONY: \ test \ docs \ @@ -14,11 +18,16 @@ endif release-linux \ release-darwin +default: + cd cmd/pomo && \ + go install -ldflags '${LDFLAGS}' + bin/pomo: test - go build -o $@ + cd cmd/pomo && \ + go build -ldflags '${LDFLAGS}' -o ../../$@ -bindata.go: tomato-icon.png - go-bindata -pkg main -o $@ $^ +#bindata.go: tomato-icon.png +# go-bindata -pkg main -o $@ $^ test: go test ./... @@ -31,16 +40,16 @@ bin/pomo-linux: bin/pomo-$(VERSION)-linux-amd64 bin/pomo-darwin: bin/pomo-$(VERSION)-darwin-amd64 -bin/pomo-$(VERSION)-linux-amd64: bin bindata.go - $(DOCKER_CMD) --env GOOS=linux --env GOARCH=amd64 $(DOCKER_IMAGE) go build -ldflags "-X main.Version=$(VERSION)" -o $@ +bin/pomo-$(VERSION)-linux-amd64: bin + $(DOCKER_CMD) --env GOOS=linux --env GOARCH=amd64 $(DOCKER_IMAGE) go build -ldflags "${LDFLAGS}" -o $@ bin/pomo-$(VERSION)-linux-amd64.md5: md5sum bin/pomo-$(VERSION)-linux-amd64 | sed -e 's/bin\///' > $@ -bin/pomo-$(VERSION)-darwin-amd64: bin bindata.go +bin/pomo-$(VERSION)-darwin-amd64: bin # This is used to cross-compile a Darwin compatible Mach-O executable # on Linux for OSX, you need to install https://github.com/tpoechtrager/osxcross - $(DOCKER_CMD) --env GOOS=darwin --env GOARCH=amd64 --env CC=x86_64-apple-darwin15-cc --env CGO_ENABLED=1 $(DOCKER_IMAGE) go build -ldflags "-X main.Version=$(VERSION)" -o $@ + $(DOCKER_CMD) --env GOOS=darwin --env GOARCH=amd64 --env CC=x86_64-apple-darwin15-cc --env CGO_ENABLED=1 $(DOCKER_IMAGE) go build -ldflags "${LDFLAGS}" -o $@ bin/pomo-$(VERSION)-darwin-amd64.md5: diff --git a/cmd/pomo/main.go b/cmd/pomo/main.go new file mode 100644 index 0000000..d8aa4d2 --- /dev/null +++ b/cmd/pomo/main.go @@ -0,0 +1,7 @@ +package main + +import "github.com/kevinschoon/pomo/pkg/cmd" + +func main() { + cmd.Run() +} diff --git a/main.go b/pkg/cmd/cmd.go similarity index 73% rename from main.go rename to pkg/cmd/cmd.go index e8675d4..292e428 100644 --- a/main.go +++ b/pkg/cmd/cmd.go @@ -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)) diff --git a/bindata.go b/pkg/internal/bindata.go similarity index 99% rename from bindata.go rename to pkg/internal/bindata.go index 8f4bcd9..48aeb4b 100644 --- a/bindata.go +++ b/pkg/internal/bindata.go @@ -3,7 +3,7 @@ // tomato-icon.png // DO NOT EDIT! -package main +package pomo import ( "bytes" diff --git a/config.go b/pkg/internal/config.go similarity index 99% rename from config.go rename to pkg/internal/config.go index ec68006..e5090f1 100644 --- a/config.go +++ b/pkg/internal/config.go @@ -1,4 +1,4 @@ -package main +package pomo import ( "encoding/json" diff --git a/runner.go b/pkg/internal/runner.go similarity index 99% rename from runner.go rename to pkg/internal/runner.go index c6376e1..9325c74 100644 --- a/runner.go +++ b/pkg/internal/runner.go @@ -1,4 +1,4 @@ -package main +package pomo import ( "database/sql" diff --git a/runner_test.go b/pkg/internal/runner_test.go similarity index 94% rename from runner_test.go rename to pkg/internal/runner_test.go index b11c628..54a316e 100644 --- a/runner_test.go +++ b/pkg/internal/runner_test.go @@ -1,4 +1,4 @@ -package main +package pomo import ( "fmt" @@ -14,7 +14,7 @@ func TestTaskRunner(t *testing.T) { if err != nil { t.Error(err) } - err = initDB(store) + err = InitDB(store) if err != nil { t.Error(err) } diff --git a/server.go b/pkg/internal/server.go similarity index 99% rename from server.go rename to pkg/internal/server.go index 87c5c7e..38357c7 100644 --- a/server.go +++ b/pkg/internal/server.go @@ -1,4 +1,4 @@ -package main +package pomo import ( "encoding/json" diff --git a/store.go b/pkg/internal/store.go similarity index 98% rename from store.go rename to pkg/internal/store.go index f3bf795..76a0906 100644 --- a/store.go +++ b/pkg/internal/store.go @@ -1,4 +1,4 @@ -package main +package pomo import ( "database/sql" @@ -168,7 +168,7 @@ func (s Store) DeletePomodoros(tx *sql.Tx, taskID int) error { func (s Store) Close() error { return s.db.Close() } -func initDB(db *Store) error { +func InitDB(db *Store) error { stmt := ` CREATE TABLE task ( message TEXT, diff --git a/types.go b/pkg/internal/types.go similarity index 99% rename from types.go rename to pkg/internal/types.go index d248aed..d52c2e6 100644 --- a/types.go +++ b/pkg/internal/types.go @@ -1,4 +1,4 @@ -package main +package pomo import ( "io/ioutil" diff --git a/ui.go b/pkg/internal/ui.go similarity index 97% rename from ui.go rename to pkg/internal/ui.go index f9b42fc..4aa5f99 100644 --- a/ui.go +++ b/pkg/internal/ui.go @@ -1,4 +1,4 @@ -package main +package pomo import ( "fmt" @@ -86,7 +86,7 @@ func centered(part termui.GridBufferer) *termui.Grid { return grid } -func startUI(runner *TaskRunner) { +func StartUI(runner *TaskRunner) { err := termui.Init() if err != nil { panic(err) diff --git a/util.go b/pkg/internal/util.go similarity index 84% rename from util.go rename to pkg/internal/util.go index 4c2425f..70b4433 100644 --- a/util.go +++ b/pkg/internal/util.go @@ -1,29 +1,14 @@ -package main +package pomo import ( "fmt" - "os" - "os/user" - "path" "time" "github.com/fatih/color" ) -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 summerizeTasks(config *Config, tasks []*Task) { +func SummerizeTasks(config *Config, tasks []*Task) { for _, task := range tasks { var start string if len(task.Pomodoros) > 0 { @@ -83,7 +68,7 @@ func summerizeTasks(config *Config, tasks []*Task) { } } -func outputStatus(status Status) { +func OutputStatus(status Status) { state := "?" if status.State >= RUNNING { state = string(status.State.String()[0]) diff --git a/version.go b/pkg/internal/version.go similarity index 67% rename from version.go rename to pkg/internal/version.go index 3cb07c8..aad0e90 100644 --- a/version.go +++ b/pkg/internal/version.go @@ -1,3 +1,3 @@ -package main +package pomo var Version = "undefined"