add tags
This commit is contained in:
parent
b6c74bb61a
commit
6dab576f27
2
main.go
2
main.go
|
@ -43,6 +43,7 @@ func start(path *string) func(*cli.Cmd) {
|
||||||
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")
|
||||||
message = cmd.StringArg("MESSAGE", "", "descriptive name of the given task")
|
message = cmd.StringArg("MESSAGE", "", "descriptive name of the given task")
|
||||||
|
tags = cmd.StringsOpt("t tag", []string{}, "tags associated with this task")
|
||||||
)
|
)
|
||||||
cmd.Action = func() {
|
cmd.Action = func() {
|
||||||
parsed, err := time.ParseDuration(*duration)
|
parsed, err := time.ParseDuration(*duration)
|
||||||
|
@ -52,6 +53,7 @@ func start(path *string) func(*cli.Cmd) {
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
task := Task{
|
task := Task{
|
||||||
Message: *message,
|
Message: *message,
|
||||||
|
Tags: *tags,
|
||||||
count: *count,
|
count: *count,
|
||||||
duration: parsed,
|
duration: parsed,
|
||||||
}
|
}
|
||||||
|
|
12
store.go
12
store.go
|
@ -5,6 +5,7 @@ import (
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -36,7 +37,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 (message) VALUES ($1)", task.Message)
|
_, err = tx.Exec("INSERT INTO task (message,tags) VALUES ($1,$2)", task.Message, strings.Join(task.Tags, ","))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return -1, err
|
return -1, err
|
||||||
|
@ -60,17 +61,19 @@ 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,message FROM task`)
|
rows, err := s.db.Query(`SELECT rowid,message,tags FROM task`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
tasks := []*Task{}
|
tasks := []*Task{}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
|
var tags string
|
||||||
task := &Task{Records: []*Record{}}
|
task := &Task{Records: []*Record{}}
|
||||||
err = rows.Scan(&task.ID, &task.Message)
|
err = rows.Scan(&task.ID, &task.Message, &tags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
task.Tags = strings.Split(tags, ",")
|
||||||
records, err := s.ReadRecords(task.ID)
|
records, err := s.ReadRecords(task.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -131,7 +134,8 @@ 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,
|
||||||
|
tags TEXT
|
||||||
);
|
);
|
||||||
CREATE TABLE record (
|
CREATE TABLE record (
|
||||||
task_id INTEGER,
|
task_id INTEGER,
|
||||||
|
|
8
types.go
8
types.go
|
@ -7,9 +7,11 @@ import (
|
||||||
|
|
||||||
// Task describes some activity
|
// Task describes some activity
|
||||||
type Task struct {
|
type Task struct {
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
Records []*Record `json:"records"`
|
Records []*Record `json:"records"`
|
||||||
|
// Free-form tags associated with this task
|
||||||
|
Tags []string `json:"tags"`
|
||||||
count int
|
count int
|
||||||
duration time.Duration
|
duration time.Duration
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue