Skip to content

Commit

Permalink
Add -h, --help flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcus Gartner committed Oct 22, 2019
1 parent 8395cbd commit 5ba936c
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
package main

import (
"flag"
"fmt"
"os"

"pg_flame/pkg/flame"
"pg_flame/pkg/html"
"pg_flame/pkg/plan"
)

var (
version = "1.0"
hFlag = flag.Bool("h", false, "print help info")
helpFlag = flag.Bool("help", false, "print help info")
)

func main() {
flag.Parse()

if *hFlag || *helpFlag {
printHelp()
}

err, p := plan.New(os.Stdin)
if err != nil {
handleErr(err)
Expand All @@ -27,3 +41,26 @@ func handleErr(err error) {
fmt.Println(msg)
os.Exit(1)
}

func printHelp() {
help := `pg_flame %s
Turn Postgres query plans into flamegraphs.
Usage:
pg_flame [options]
Without Options:
Reads a JSON query plan from standard input and writes the
flamegraph html to standard output.
Options:
-h, --help print help information
`

fmt.Printf(help, version)
os.Exit(0)
}

0 comments on commit 5ba936c

Please sign in to comment.