Allow pomo status --json

This commit is contained in:
Amiel Martin 2021-10-13 13:10:13 -08:00
parent c7cdf725ab
commit c6c3e43991
No known key found for this signature in database
GPG Key ID: EBD5DF39BDE06E84
1 changed files with 14 additions and 2 deletions

View File

@ -257,18 +257,30 @@ pomo delete 5 10 20
func _status(config *pomo.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]"
var asJSON = cmd.BoolOpt("json", false, "output task history as JSON")
cmd.Action = func() { cmd.Action = func() {
client, err := pomo.NewClient(config.SocketPath) client, err := pomo.NewClient(config.SocketPath)
if err != nil { if err != nil {
if *asJSON {
maybe(json.NewEncoder(os.Stdout).Encode(pomo.Status{}))
} else {
fmt.Println(pomo.FormatStatus(pomo.Status{})) fmt.Println(pomo.FormatStatus(pomo.Status{}))
}
return return
} }
defer client.Close() defer client.Close()
status, err := client.Status() status, err := client.Status()
maybe(err) maybe(err)
if *asJSON {
maybe(json.NewEncoder(os.Stdout).Encode(status))
} else {
fmt.Println(pomo.FormatStatus(*status)) fmt.Println(pomo.FormatStatus(*status))
} }
} }
}
} }
func _config(config *pomo.Config) func(*cli.Cmd) { func _config(config *pomo.Config) func(*cli.Cmd) {