Merge pull request #35 from kevinschoon/cleanup_project_structure

restructure project into modules
This commit is contained in:
Kevin Schoon 2020-09-10 08:51:39 -05:00 committed by GitHub
commit 333eb1fbe5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 92 additions and 197 deletions

90
Gopkg.lock generated
View File

@ -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

View File

@ -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"

View File

@ -1,10 +1,14 @@
DOCKER_CMD=docker run --rm -ti -w /build/pomo -v $$PWD:/build/pomo DOCKER_CMD=docker run --rm -ti -w /build/pomo -v $$PWD:/build/pomo
DOCKER_IMAGE=pomo-build DOCKER_IMAGE=pomo-build
VERSION ?= $(shell git describe --tags 2>/dev/null) VERSION ?= $(shell git describe --tags 2>/dev/null)
ifeq "$(VERSION)" "" ifeq "$(VERSION)" ""
VERSION := UNKNOWN VERSION := UNKNOWN
endif endif
LDFLAGS=\
-X github.com/kevinschoon/pomo/pkg/internal/version.Version=$(VERSION)
.PHONY: \ .PHONY: \
test \ test \
docs \ docs \
@ -14,11 +18,16 @@ endif
release-linux \ release-linux \
release-darwin release-darwin
bin/pomo: test default:
go build -o $@ cd cmd/pomo && \
go install -ldflags '${LDFLAGS}'
bindata.go: tomato-icon.png bin/pomo: test
go-bindata -pkg main -o $@ $^ cd cmd/pomo && \
go build -ldflags '${LDFLAGS}' -o ../../$@
#bindata.go: tomato-icon.png
# go-bindata -pkg main -o $@ $^
test: test:
go 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-darwin: bin/pomo-$(VERSION)-darwin-amd64
bin/pomo-$(VERSION)-linux-amd64: bin bindata.go bin/pomo-$(VERSION)-linux-amd64: bin
$(DOCKER_CMD) --env GOOS=linux --env GOARCH=amd64 $(DOCKER_IMAGE) go build -ldflags "-X main.Version=$(VERSION)" -o $@ $(DOCKER_CMD) --env GOOS=linux --env GOARCH=amd64 $(DOCKER_IMAGE) go build -ldflags "${LDFLAGS}" -o $@
bin/pomo-$(VERSION)-linux-amd64.md5: bin/pomo-$(VERSION)-linux-amd64.md5:
md5sum bin/pomo-$(VERSION)-linux-amd64 | sed -e 's/bin\///' > $@ 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 # 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 # 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: bin/pomo-$(VERSION)-darwin-amd64.md5:

7
cmd/pomo/main.go Normal file
View File

@ -0,0 +1,7 @@
package main
import "github.com/kevinschoon/pomo/pkg/cmd"
func main() {
cmd.Run()
}

View File

@ -1,17 +1,34 @@
package main package cmd
import ( import (
"database/sql" "database/sql"
"encoding/json" "encoding/json"
"fmt" "fmt"
"os" "os"
"os/user"
"path"
"sort" "sort"
"time" "time"
cli "github.com/jawher/mow.cli" 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) { return func(cmd *cli.Cmd) {
cmd.Spec = "[OPTIONS] MESSAGE" cmd.Spec = "[OPTIONS] MESSAGE"
var ( var (
@ -23,10 +40,10 @@ func start(config *Config) func(*cli.Cmd) {
cmd.Action = func() { cmd.Action = func() {
parsed, err := time.ParseDuration(*duration) parsed, err := time.ParseDuration(*duration)
maybe(err) maybe(err)
db, err := NewStore(config.DBPath) db, err := pomo.NewStore(config.DBPath)
maybe(err) maybe(err)
defer db.Close() defer db.Close()
task := &Task{ task := &pomo.Task{
Message: *message, Message: *message,
Tags: *tags, Tags: *tags,
NPomodoros: *pomodoros, NPomodoros: *pomodoros,
@ -40,19 +57,19 @@ func start(config *Config) func(*cli.Cmd) {
task.ID = id task.ID = id
return nil return nil
})) }))
runner, err := NewTaskRunner(task, config) runner, err := pomo.NewTaskRunner(task, config)
maybe(err) maybe(err)
server, err := NewServer(runner, config) server, err := pomo.NewServer(runner, config)
maybe(err) maybe(err)
server.Start() server.Start()
defer server.Stop() defer server.Stop()
runner.Start() 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) { return func(cmd *cli.Cmd) {
cmd.Spec = "[OPTIONS] MESSAGE" cmd.Spec = "[OPTIONS] MESSAGE"
var ( var (
@ -64,10 +81,10 @@ func create(config *Config) func(*cli.Cmd) {
cmd.Action = func() { cmd.Action = func() {
parsed, err := time.ParseDuration(*duration) parsed, err := time.ParseDuration(*duration)
maybe(err) maybe(err)
db, err := NewStore(config.DBPath) db, err := pomo.NewStore(config.DBPath)
maybe(err) maybe(err)
defer db.Close() defer db.Close()
task := &Task{ task := &pomo.Task{
Message: *message, Message: *message,
Tags: *tags, Tags: *tags,
NPomodoros: *pomodoros, 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) { return func(cmd *cli.Cmd) {
cmd.Spec = "[OPTIONS] TASK_ID" cmd.Spec = "[OPTIONS] TASK_ID"
var ( var (
@ -93,10 +110,10 @@ func begin(config *Config) func(*cli.Cmd) {
) )
cmd.Action = func() { cmd.Action = func() {
db, err := NewStore(config.DBPath) db, err := pomo.NewStore(config.DBPath)
maybe(err) maybe(err)
defer db.Close() defer db.Close()
var task *Task var task *pomo.Task
maybe(db.With(func(tx *sql.Tx) error { maybe(db.With(func(tx *sql.Tx) error {
read, err := db.ReadTask(tx, *taskId) read, err := db.ReadTask(tx, *taskId)
if err != nil { if err != nil {
@ -107,34 +124,34 @@ func begin(config *Config) func(*cli.Cmd) {
if err != nil { if err != nil {
return err return err
} }
task.Pomodoros = []*Pomodoro{} task.Pomodoros = []*pomo.Pomodoro{}
return nil return nil
})) }))
runner, err := NewTaskRunner(task, config) runner, err := pomo.NewTaskRunner(task, config)
maybe(err) maybe(err)
server, err := NewServer(runner, config) server, err := pomo.NewServer(runner, config)
maybe(err) maybe(err)
server.Start() server.Start()
defer server.Stop() defer server.Stop()
runner.Start() 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) { return func(cmd *cli.Cmd) {
cmd.Spec = "[OPTIONS]" cmd.Spec = "[OPTIONS]"
cmd.Action = func() { cmd.Action = func() {
db, err := NewStore(config.DBPath) db, err := pomo.NewStore(config.DBPath)
maybe(err) maybe(err)
defer db.Close() 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) { return func(cmd *cli.Cmd) {
cmd.Spec = "[OPTIONS]" cmd.Spec = "[OPTIONS]"
var ( var (
@ -147,17 +164,17 @@ func list(config *Config) func(*cli.Cmd) {
cmd.Action = func() { cmd.Action = func() {
duration, err := time.ParseDuration(*duration) duration, err := time.ParseDuration(*duration)
maybe(err) maybe(err)
db, err := NewStore(config.DBPath) db, err := pomo.NewStore(config.DBPath)
maybe(err) maybe(err)
defer db.Close() defer db.Close()
maybe(db.With(func(tx *sql.Tx) error { maybe(db.With(func(tx *sql.Tx) error {
tasks, err := db.ReadTasks(tx) tasks, err := db.ReadTasks(tx)
maybe(err) maybe(err)
if *assend { if *assend {
sort.Sort(sort.Reverse(ByID(tasks))) sort.Sort(sort.Reverse(pomo.ByID(tasks)))
} }
if !*all { if !*all {
tasks = After(time.Now().Add(-duration), tasks) tasks = pomo.After(time.Now().Add(-duration), tasks)
} }
if *limit > 0 && (len(tasks) > *limit) { if *limit > 0 && (len(tasks) > *limit) {
tasks = tasks[0:*limit] tasks = tasks[0:*limit]
@ -167,19 +184,19 @@ func list(config *Config) func(*cli.Cmd) {
return nil return nil
} }
maybe(err) maybe(err)
summerizeTasks(config, tasks) pomo.SummerizeTasks(config, tasks)
return nil return nil
})) }))
} }
} }
} }
func _delete(config *Config) func(*cli.Cmd) { func _delete(config *pomo.Config) func(*cli.Cmd) {
return func(cmd *cli.Cmd) { return func(cmd *cli.Cmd) {
cmd.Spec = "[OPTIONS] TASK_ID" cmd.Spec = "[OPTIONS] TASK_ID"
var taskID = cmd.IntArg("TASK_ID", -1, "task to delete") var taskID = cmd.IntArg("TASK_ID", -1, "task to delete")
cmd.Action = func() { cmd.Action = func() {
db, err := NewStore(config.DBPath) db, err := pomo.NewStore(config.DBPath)
maybe(err) maybe(err)
defer db.Close() defer db.Close()
maybe(db.With(func(tx *sql.Tx) error { 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) { return func(cmd *cli.Cmd) {
cmd.Spec = "[OPTIONS]" cmd.Spec = "[OPTIONS]"
cmd.Action = func() { cmd.Action = func() {
client, err := NewClient(config.SocketPath) client, err := pomo.NewClient(config.SocketPath)
if err != nil { if err != nil {
outputStatus(Status{}) pomo.OutputStatus(pomo.Status{})
return return
} }
defer client.Close() defer client.Close()
status, err := client.Status() status, err := client.Status()
maybe(err) 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) { return func(cmd *cli.Cmd) {
cmd.Spec = "[OPTIONS]" cmd.Spec = "[OPTIONS]"
cmd.Action = func() { 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 := 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.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]" app.Spec = "[OPTIONS]"
var ( var (
config = &Config{} config = &pomo.Config{}
path = app.StringOpt("p path", defaultConfigPath(), "path to the pomo config directory") path = app.StringOpt("p path", defaultConfigPath(), "path to the pomo config directory")
) )
app.Before = func() { 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("start s", "start a new task", start(config))
app.Command("init", "initialize the sqlite database", initialize(config)) app.Command("init", "initialize the sqlite database", initialize(config))
app.Command("config cf", "display the current configuration", _config(config)) app.Command("config cf", "display the current configuration", _config(config))

View File

@ -3,7 +3,7 @@
// tomato-icon.png // tomato-icon.png
// DO NOT EDIT! // DO NOT EDIT!
package main package pomo
import ( import (
"bytes" "bytes"

View File

@ -1,4 +1,4 @@
package main package pomo
import ( import (
"encoding/json" "encoding/json"

View File

@ -1,4 +1,4 @@
package main package pomo
import ( import (
"database/sql" "database/sql"

View File

@ -1,4 +1,4 @@
package main package pomo
import ( import (
"fmt" "fmt"
@ -14,7 +14,7 @@ func TestTaskRunner(t *testing.T) {
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
err = initDB(store) err = InitDB(store)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }

View File

@ -1,4 +1,4 @@
package main package pomo
import ( import (
"encoding/json" "encoding/json"

View File

@ -1,4 +1,4 @@
package main package pomo
import ( import (
"database/sql" "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 (s Store) Close() error { return s.db.Close() }
func initDB(db *Store) error { func InitDB(db *Store) error {
stmt := ` stmt := `
CREATE TABLE task ( CREATE TABLE task (
message TEXT, message TEXT,

View File

@ -1,4 +1,4 @@
package main package pomo
import ( import (
"io/ioutil" "io/ioutil"

View File

@ -1,4 +1,4 @@
package main package pomo
import ( import (
"fmt" "fmt"
@ -86,7 +86,7 @@ func centered(part termui.GridBufferer) *termui.Grid {
return grid return grid
} }
func startUI(runner *TaskRunner) { func StartUI(runner *TaskRunner) {
err := termui.Init() err := termui.Init()
if err != nil { if err != nil {
panic(err) panic(err)

View File

@ -1,29 +1,14 @@
package main package pomo
import ( import (
"fmt" "fmt"
"os"
"os/user"
"path"
"time" "time"
"github.com/fatih/color" "github.com/fatih/color"
) )
func maybe(err error) {
if err != nil {
fmt.Printf("Error:\n%s\n", err)
os.Exit(1)
}
}
func defaultConfigPath() string { func SummerizeTasks(config *Config, tasks []*Task) {
u, err := user.Current()
maybe(err)
return path.Join(u.HomeDir, "/.pomo/config.json")
}
func summerizeTasks(config *Config, tasks []*Task) {
for _, task := range tasks { for _, task := range tasks {
var start string var start string
if len(task.Pomodoros) > 0 { if len(task.Pomodoros) > 0 {
@ -83,7 +68,7 @@ func summerizeTasks(config *Config, tasks []*Task) {
} }
} }
func outputStatus(status Status) { func OutputStatus(status Status) {
state := "?" state := "?"
if status.State >= RUNNING { if status.State >= RUNNING {
state = string(status.State.String()[0]) state = string(status.State.String()[0])

View File

@ -1,3 +1,3 @@
package main package pomo
var Version = "undefined" var Version = "undefined"