Skip to content

Commit

Permalink
Setting version and build time from build.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
mrichman committed Oct 18, 2016
1 parent 552852f commit 0d27bbf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
10 changes: 10 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

VERSION=`git describe --tags`
CURRENT=`pwd`
BASENAME=`basename "$CURRENT"`
MAIN=cmd/${BASENAME}/main.go
DATE=`date --rfc-3339=seconds | sed 's/ /T/'`
LDFLAGS="-X main.Version=${VERSION} -X main.BuildTime=${DATE}"

go build -ldflags "${LDFLAGS}" -o ${BASENAME} ${MAIN}
19 changes: 14 additions & 5 deletions cmd/hargo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import (
"github.com/urfave/cli"
)

var version = "0.1.0-dev"
var (
// Version is set by build.sh ldflags
Version string
// BuildTime is set by build.sh ldflags
BuildTime string
)

const usage = "work with HTTP Archive (.har) files"

Expand All @@ -27,8 +32,8 @@ func main() {

app := cli.NewApp()
app.Name = "hargo"
app.Version = version
app.Compiled = time.Now()
app.Version = Version + " (" + BuildTime + ")"
app.Compiled, _ = time.Parse(time.RFC3339, BuildTime)
app.Authors = []cli.Author{
{
Name: "Mark A. Richman",
Expand All @@ -47,7 +52,6 @@ func main() {
Usage: "Show debug output"},
}


app.Commands = []cli.Command{
{
Name: "fetch",
Expand Down Expand Up @@ -82,7 +86,12 @@ func main() {
file, err := os.Open(harFile)
if err == nil {
r := newReader(file)
cmd, _ := hargo.ToCurl(r)
cmd, err := hargo.ToCurl(r)

if err != nil {
log.Error(err)
}

fmt.Println(cmd)
} else {
log.Fatal("Cannot open file: ", harFile)
Expand Down

0 comments on commit 0d27bbf

Please sign in to comment.