mirror of https://github.com/status-im/fathom.git
add --json flag to stats command
This commit is contained in:
parent
01474759c6
commit
c71907033e
|
@ -1,9 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/urfave/cli"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -20,6 +22,10 @@ var statsCmd = cli.Command{
|
|||
Name: "end-date",
|
||||
Usage: "end date, expects a date in format 2006-01-02",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "json",
|
||||
Usage: "get a json response",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -39,6 +45,14 @@ func stats(c *cli.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if c.Bool("json") {
|
||||
if err := json.NewEncoder(os.Stdout).Encode(result); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
fmt.Printf("%s - %s\n", start.Format("Jan 01, 2006"), end.Format("Jan 01, 2006"))
|
||||
fmt.Printf("===========================\n")
|
||||
fmt.Printf("Visitors: \t%d\n", result.Visitors)
|
||||
|
|
Loading…
Reference in New Issue