Skip to content

Commit 0d27bbf

Browse files
committed
Setting version and build time from build.sh
1 parent 552852f commit 0d27bbf

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

build.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
VERSION=`git describe --tags`
4+
CURRENT=`pwd`
5+
BASENAME=`basename "$CURRENT"`
6+
MAIN=cmd/${BASENAME}/main.go
7+
DATE=`date --rfc-3339=seconds | sed 's/ /T/'`
8+
LDFLAGS="-X main.Version=${VERSION} -X main.BuildTime=${DATE}"
9+
10+
go build -ldflags "${LDFLAGS}" -o ${BASENAME} ${MAIN}

cmd/hargo/main.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ import (
1313
"github.com/urfave/cli"
1414
)
1515

16-
var version = "0.1.0-dev"
16+
var (
17+
// Version is set by build.sh ldflags
18+
Version string
19+
// BuildTime is set by build.sh ldflags
20+
BuildTime string
21+
)
1722

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

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

2833
app := cli.NewApp()
2934
app.Name = "hargo"
30-
app.Version = version
31-
app.Compiled = time.Now()
35+
app.Version = Version + " (" + BuildTime + ")"
36+
app.Compiled, _ = time.Parse(time.RFC3339, BuildTime)
3237
app.Authors = []cli.Author{
3338
{
3439
Name: "Mark A. Richman",
@@ -47,7 +52,6 @@ func main() {
4752
Usage: "Show debug output"},
4853
}
4954

50-
5155
app.Commands = []cli.Command{
5256
{
5357
Name: "fetch",
@@ -82,7 +86,12 @@ func main() {
8286
file, err := os.Open(harFile)
8387
if err == nil {
8488
r := newReader(file)
85-
cmd, _ := hargo.ToCurl(r)
89+
cmd, err := hargo.ToCurl(r)
90+
91+
if err != nil {
92+
log.Error(err)
93+
}
94+
8695
fmt.Println(cmd)
8796
} else {
8897
log.Fatal("Cannot open file: ", harFile)

0 commit comments

Comments
 (0)