wrap commands with parent cli closure
This commit is contained in:
parent
b4169c3d6f
commit
e782c4edd0
33
main.go
33
main.go
|
@ -36,13 +36,13 @@ func startTask(task Task, prompter Prompter, db *Store) {
|
|||
|
||||
}
|
||||
|
||||
func start(cmd *cli.Cmd) {
|
||||
func start(path *string) func(*cli.Cmd) {
|
||||
return func(cmd *cli.Cmd) {
|
||||
cmd.Spec = "[OPTIONS] MESSAGE"
|
||||
var (
|
||||
duration = cmd.StringOpt("d duration", "25m", "duration of each stent")
|
||||
count = cmd.IntOpt("c count", 4, "number of working stents")
|
||||
message = cmd.StringArg("MESSAGE", "", "descriptive name of the given task")
|
||||
path = cmd.StringOpt("p path", defaultDBPath(), "path to the pomo state directory")
|
||||
)
|
||||
cmd.Action = func() {
|
||||
parsed, err := time.ParseDuration(*duration)
|
||||
|
@ -57,25 +57,23 @@ func start(cmd *cli.Cmd) {
|
|||
}
|
||||
startTask(task, &I3{}, db)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func initialize(cmd *cli.Cmd) {
|
||||
func initialize(path *string) func(*cli.Cmd) {
|
||||
return func(cmd *cli.Cmd) {
|
||||
cmd.Spec = "[OPTIONS]"
|
||||
var (
|
||||
path = cmd.StringOpt("p path", defaultDBPath(), "path to the pomo state directory")
|
||||
)
|
||||
cmd.Action = func() {
|
||||
db, err := NewStore(*path)
|
||||
maybe(err)
|
||||
defer db.Close()
|
||||
maybe(initDB(db))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func list(cmd *cli.Cmd) {
|
||||
var (
|
||||
path = cmd.StringOpt("p path", defaultDBPath(), "path to the pomo state directory")
|
||||
)
|
||||
func list(path *string) func(*cli.Cmd) {
|
||||
return func(cmd *cli.Cmd) {
|
||||
cmd.Action = func() {
|
||||
db, err := NewStore(*path)
|
||||
maybe(err)
|
||||
|
@ -84,13 +82,22 @@ func list(cmd *cli.Cmd) {
|
|||
maybe(err)
|
||||
maybe(json.NewEncoder(os.Stdout).Encode(tasks))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func _delete(path *string) func(*cli.Cmd) {
|
||||
return func(cmd *cli.Cmd) {}
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := cli.App("pomo", "Pomodoro CLI")
|
||||
app.Spec = "[OPTIONS]"
|
||||
app.Command("start", "start a new task", start)
|
||||
app.Command("init", "initialize the sqlite database", initialize)
|
||||
app.Command("ls", "list historical tasks", list)
|
||||
var (
|
||||
path = app.StringOpt("p path", defaultDBPath(), "path to the pomo state directory")
|
||||
)
|
||||
app.Command("start s", "start a new task", start(path))
|
||||
app.Command("init", "initialize the sqlite database", initialize(path))
|
||||
app.Command("list l", "list historical tasks", list(path))
|
||||
app.Command("delete d", "delete a stored task", _delete(path))
|
||||
app.Run(os.Args)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue