Skip to content

Commit 67b1962

Browse files
Added Makefile, .gitignore, deps and --version
1 parent 74d83d5 commit 67b1962

File tree

5 files changed

+98
-7
lines changed

5 files changed

+98
-7
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
random_data_load*
2+
vendor/

Gopkg.lock

+16-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

+8
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
branch = "master"
3030
name = "github.com/gosuri/uiprogress"
3131

32+
[[constraint]]
33+
branch = "master"
34+
name = "github.com/hashicorp/go-version"
35+
3236
[[constraint]]
3337
branch = "master"
3438
name = "github.com/icrowley/fake"
@@ -37,6 +41,10 @@
3741
branch = "master"
3842
name = "github.com/kr/pretty"
3943

44+
[[constraint]]
45+
name = "github.com/pkg/errors"
46+
version = "0.8.0"
47+
4048
[[constraint]]
4149
name = "gopkg.in/alecthomas/kingpin.v2"
4250
version = "2.2.5"

Makefile

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
GO := go
2+
pkgs = $(shell basename `git rev-parse --show-toplevel`)
3+
VERSION=$(shell git describe --abbrev=0)
4+
BUILD=$(shell date +%FT%T%z)
5+
GOVERSION=$(shell go version | cut --delimiter=" " -f3)
6+
COMMIT=$(shell git rev-parse HEAD)
7+
BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
8+
9+
PREFIX=$(shell pwd)
10+
TOP_DIR=$(shell git rev-parse --show-toplevel)
11+
BIN_DIR=$(shell git rev-parse --show-toplevel)/bin
12+
SRC_DIR=$(shell git rev-parse --show-toplevel)/src/go
13+
LDFLAGS="-X main.Version=${VERSION} -X main.Build=${BUILD} -X main.Commit=${COMMIT} -X main.Branch=${BRANCH} -X main.GoVersion=${GOVERSION} -s -w"
14+
15+
.PHONY: all style format build test vet tarball linux-amd64
16+
17+
all: clean linux-amd64 darwin-amd64
18+
19+
clean:
20+
@echo "Cleaning binaries dir ${BIN_DIR}"
21+
@rm -rf ${BIN_DIR}/ 2> /dev/null
22+
23+
linux-amd64:
24+
@echo "Building linux/amd64 binaries in ${BIN_DIR}"
25+
@mkdir -p ${BIN_DIR}
26+
@$(foreach pkg,$(pkgs),GOOS=linux GOARCH=amd64 go build -ldflags ${LDFLAGS} -o ${BIN_DIR}/$(pkg)_linux_amd64 ./;)
27+
28+
linux-386:
29+
@echo "Building linux/386 binaries in ${BIN_DIR}"
30+
@mkdir -p ${BIN_DIR}
31+
@$(foreach pkg,$(pkgs),GOOS=linux GOARCH=386 go build -ldflags ${LDFLAGS} -o ${BIN_DIR}/$(pkg)_linux_386 ./;)
32+
33+
darwin-amd64:
34+
@echo "Building darwin/amd64 binaries in ${BIN_DIR}"
35+
@mkdir -p ${BIN_DIR}
36+
@$(foreach pkg,$(pkgs),GOOS=darwin GOARCH=amd64 go build -ldflags ${LDFLAGS} -o ${BIN_DIR}/$(pkg)_darwin_amd64 ./;)
37+
38+
style:
39+
@echo ">> checking code style"
40+
@! gofmt -d $(shell find . -path ./vendor -prune -o -name '*.go' -print) | grep '^'
41+
42+
test:
43+
@echo ">> running tests"
44+
@./runtests.sh
45+
46+
format:
47+
@echo ">> formatting code"
48+
@$(GO) fmt $(pkgs)
49+
50+
vet:
51+
@echo ">> vetting code"
52+
@$(GO) vet $(pkgs)
53+

main.go

+19-3
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ var (
3434
progress = app.Flag("show-progressbar", "Show progress bar").Default("true").Bool()
3535
samples = app.Flag("max-fk-samples", "Maximum number of samples for foreign keys fields").Default("100").Int64()
3636
factor = app.Flag("fk-samples-factor", "Percentage used to get random samples for foreign keys fields").Default("0.3").Float64()
37+
version = app.Flag("version", "Show version and exit").Bool()
3738
//
38-
schema = app.Arg("database", "Database").Required().String()
39-
tableName = app.Arg("table", "Table").Required().String()
40-
rows = app.Arg("rows", "Number of rows to insert").Required().Int()
39+
schema = app.Arg("database", "Database").String()
40+
tableName = app.Arg("table", "Table").String()
41+
rows = app.Arg("rows", "Number of rows to insert").Int()
4142

4243
validFunctions = []string{"int", "string", "date", "date_in_range"}
4344
maxValues = map[string]int64{
@@ -51,6 +52,12 @@ var (
5152
"double": 0x7FFFFFFF,
5253
"bigint": 0x7FFFFFFFFFFFFFFF,
5354
}
55+
56+
Version = "0.0.0."
57+
Commit = "<sha1>"
58+
Branch = "branch-name"
59+
Build = "2017-01-01"
60+
GoVersion = "1.9.2"
5461
)
5562

5663
type insertValues []getters.Getter
@@ -66,6 +73,15 @@ func (g insertValues) String() string {
6673
func main() {
6774
kingpin.MustParse(app.Parse(os.Args[1:]))
6875

76+
if *version {
77+
fmt.Printf("Version : %s\n", Version)
78+
fmt.Printf("Commit : %s\n", Commit)
79+
fmt.Printf("Branch : %s\n", Branch)
80+
fmt.Printf("Build : %s\n", Build)
81+
fmt.Printf("Go version: %s\n", GoVersion)
82+
return
83+
}
84+
6985
address := *host
7086
net := "unix"
7187
if address != "localhost" {

0 commit comments

Comments
 (0)