Skip to content

Commit

Permalink
Adds version information to builds; fixes #19
Browse files Browse the repository at this point in the history
  • Loading branch information
tomnomnom committed Sep 3, 2016
1 parent 02f6d7b commit 161e241
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.mkd
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Changelog

## HEAD
## 0.3.3
- Slightly improved error reporting when ungronning
- 20 second timeout on HTTP(s) requests (thanks @gummiboll!)
- Version information added at build time + `--version` option (issue #19)

## 0.3.2
- Adds handling of `--` lines produced by grep -A etc (issue #15)
Expand Down
1 change: 1 addition & 0 deletions README.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ Usage:
Options:
-u, --ungron Reverse the operation (turn assignments back into JSON)
-m, --monochrome Monochrome (don't colorize output)
--version Print version information
Exit Codes:
0 OK
Expand Down
17 changes: 16 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/pkg/errors"
)

// Exit codes
const (
exitOK = iota
exitOpenFile
Expand All @@ -25,6 +26,7 @@ const (
exitJSONEncode
)

// Output colors
var (
strColor = color.New(color.FgYellow)
braceColor = color.New(color.FgMagenta)
Expand All @@ -33,6 +35,10 @@ var (
boolColor = color.New(color.FgCyan)
)

// gronVersion stores the current gron version, set at build
// time with the ldflags -X option
var gronVersion = "dev"

func init() {
flag.Usage = func() {
h := "Transform JSON (from a file, URL, or stdin) into discrete assignments to make it greppable\n\n"
Expand All @@ -42,7 +48,8 @@ func init() {

h += "Options:\n"
h += " -u, --ungron Reverse the operation (turn assignments back into JSON)\n"
h += " -m, --monochrome Monochrome (don't colorize output)\n\n"
h += " -m, --monochrome Monochrome (don't colorize output)\n"
h += " --version Print version information\n\n"

h += "Exit Codes:\n"
h += fmt.Sprintf(" %d\t%s\n", exitOK, "OK")
Expand All @@ -68,15 +75,23 @@ func main() {
var (
ungronFlag bool
monochromeFlag bool
versionFlag bool
)

flag.BoolVar(&ungronFlag, "ungron", false, "Turn statements into JSON instead")
flag.BoolVar(&ungronFlag, "u", false, "Turn statements into JSON instead")
flag.BoolVar(&monochromeFlag, "monochrome", false, "Monochrome (don't colorize output)")
flag.BoolVar(&monochromeFlag, "m", false, "Monochrome (don't colorize output)")
flag.BoolVar(&versionFlag, "version", false, "Print version information")

flag.Parse()

// Print version information
if versionFlag {
fmt.Printf("gron version %s\n", gronVersion)
os.Exit(exitOK)
}

var raw io.Reader

filename := flag.Arg(0)
Expand Down
2 changes: 1 addition & 1 deletion script/release
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ for ARCH in "amd64" "386"; do

rm -f ${BINFILE}

GOOS=${OS} GOARCH=${ARCH} go build github.com/${USER}/${REPO}
GOOS=${OS} GOARCH=${ARCH} go build -ldflags "-X main.gronVersion=${VERSION}" github.com/${USER}/${REPO}

if [[ "${OS}" == "windows" ]]; then
ARCHIVE="${BINARY}-${OS}-${ARCH}-${VERSION}.zip"
Expand Down
3 changes: 2 additions & 1 deletion url.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bufio"
"fmt"
"io"
"net/http"
"strings"
Expand All @@ -21,7 +22,7 @@ func getURL(url string) (io.Reader, error) {
if err != nil {
return nil, err
}
req.Header.Set("User-Agent", "gron/0.2")
req.Header.Set("User-Agent", fmt.Sprintf("gron/%s", gronVersion))
req.Header.Set("Accept", "application/json")

resp, err := client.Do(req)
Expand Down

0 comments on commit 161e241

Please sign in to comment.