From c6c3e439919f1468ee1cafeed80b67c86212dfca Mon Sep 17 00:00:00 2001 From: Amiel Martin Date: Wed, 13 Oct 2021 13:10:13 -0800 Subject: [PATCH] Allow pomo status --json --- pkg/cmd/cmd.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/cmd/cmd.go b/pkg/cmd/cmd.go index 8540c48..6256d79 100644 --- a/pkg/cmd/cmd.go +++ b/pkg/cmd/cmd.go @@ -257,16 +257,28 @@ pomo delete 5 10 20 func _status(config *pomo.Config) func(*cli.Cmd) { return func(cmd *cli.Cmd) { cmd.Spec = "[OPTIONS]" + var asJSON = cmd.BoolOpt("json", false, "output task history as JSON") cmd.Action = func() { client, err := pomo.NewClient(config.SocketPath) if err != nil { - fmt.Println(pomo.FormatStatus(pomo.Status{})) + if *asJSON { + maybe(json.NewEncoder(os.Stdout).Encode(pomo.Status{})) + } else { + fmt.Println(pomo.FormatStatus(pomo.Status{})) + } return } defer client.Close() status, err := client.Status() maybe(err) - fmt.Println(pomo.FormatStatus(*status)) + + if *asJSON { + + maybe(json.NewEncoder(os.Stdout).Encode(status)) + + } else { + fmt.Println(pomo.FormatStatus(*status)) + } } } }