name -> message
This commit is contained in:
parent
95df3be0e9
commit
b4169c3d6f
6
main.go
6
main.go
|
@ -37,11 +37,11 @@ func startTask(task Task, prompter Prompter, db *Store) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func start(cmd *cli.Cmd) {
|
func start(cmd *cli.Cmd) {
|
||||||
cmd.Spec = "[OPTIONS] NAME"
|
cmd.Spec = "[OPTIONS] MESSAGE"
|
||||||
var (
|
var (
|
||||||
duration = cmd.StringOpt("d duration", "25m", "duration of each stent")
|
duration = cmd.StringOpt("d duration", "25m", "duration of each stent")
|
||||||
count = cmd.IntOpt("c count", 4, "number of working stents")
|
count = cmd.IntOpt("c count", 4, "number of working stents")
|
||||||
name = cmd.StringArg("NAME", "", "descriptive name of the given task")
|
message = cmd.StringArg("MESSAGE", "", "descriptive name of the given task")
|
||||||
path = cmd.StringOpt("p path", defaultDBPath(), "path to the pomo state directory")
|
path = cmd.StringOpt("p path", defaultDBPath(), "path to the pomo state directory")
|
||||||
)
|
)
|
||||||
cmd.Action = func() {
|
cmd.Action = func() {
|
||||||
|
@ -51,7 +51,7 @@ func start(cmd *cli.Cmd) {
|
||||||
maybe(err)
|
maybe(err)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
task := Task{
|
task := Task{
|
||||||
Name: *name,
|
Message: *message,
|
||||||
count: *count,
|
count: *count,
|
||||||
duration: parsed,
|
duration: parsed,
|
||||||
}
|
}
|
||||||
|
|
8
store.go
8
store.go
|
@ -36,7 +36,7 @@ func (s Store) CreateTask(task Task) (int, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec("INSERT INTO task (name) VALUES ($1)", task.Name)
|
_, err = tx.Exec("INSERT INTO task (message) VALUES ($1)", task.Message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return -1, err
|
return -1, err
|
||||||
|
@ -60,14 +60,14 @@ func (s Store) CreateRecord(taskID int, record Record) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Store) ReadTasks() ([]*Task, error) {
|
func (s Store) ReadTasks() ([]*Task, error) {
|
||||||
rows, err := s.db.Query(`SELECT rowid,name FROM task`)
|
rows, err := s.db.Query(`SELECT rowid,message FROM task`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
tasks := []*Task{}
|
tasks := []*Task{}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
task := &Task{Records: []*Record{}}
|
task := &Task{Records: []*Record{}}
|
||||||
err = rows.Scan(&task.ID, &task.Name)
|
err = rows.Scan(&task.ID, &task.Message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ 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 (
|
||||||
name TEXT
|
message TEXT
|
||||||
);
|
);
|
||||||
CREATE TABLE record (
|
CREATE TABLE record (
|
||||||
task_id INTEGER,
|
task_id INTEGER,
|
||||||
|
|
2
types.go
2
types.go
|
@ -9,7 +9,7 @@ import (
|
||||||
// Task describes some activity
|
// Task describes some activity
|
||||||
type Task struct {
|
type Task struct {
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
Name string `json:"name"`
|
Message string `json:"message"`
|
||||||
Records []*Record `json:"records"`
|
Records []*Record `json:"records"`
|
||||||
count int
|
count int
|
||||||
duration time.Duration
|
duration time.Duration
|
||||||
|
|
Loading…
Reference in New Issue