Skip to content

Commit

Permalink
Added Makefile, .gitignore, deps and --version
Browse files Browse the repository at this point in the history
  • Loading branch information
percona-csalguero committed Nov 27, 2017
1 parent 74d83d5 commit 67b1962
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
random_data_load*
vendor/
20 changes: 16 additions & 4 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
branch = "master"
name = "github.com/gosuri/uiprogress"

[[constraint]]
branch = "master"
name = "github.com/hashicorp/go-version"

[[constraint]]
branch = "master"
name = "github.com/icrowley/fake"
Expand All @@ -37,6 +41,10 @@
branch = "master"
name = "github.com/kr/pretty"

[[constraint]]
name = "github.com/pkg/errors"
version = "0.8.0"

[[constraint]]
name = "gopkg.in/alecthomas/kingpin.v2"
version = "2.2.5"
53 changes: 53 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
GO := go
pkgs = $(shell basename `git rev-parse --show-toplevel`)
VERSION=$(shell git describe --abbrev=0)
BUILD=$(shell date +%FT%T%z)
GOVERSION=$(shell go version | cut --delimiter=" " -f3)
COMMIT=$(shell git rev-parse HEAD)
BRANCH=$(shell git rev-parse --abbrev-ref HEAD)

PREFIX=$(shell pwd)
TOP_DIR=$(shell git rev-parse --show-toplevel)
BIN_DIR=$(shell git rev-parse --show-toplevel)/bin
SRC_DIR=$(shell git rev-parse --show-toplevel)/src/go
LDFLAGS="-X main.Version=${VERSION} -X main.Build=${BUILD} -X main.Commit=${COMMIT} -X main.Branch=${BRANCH} -X main.GoVersion=${GOVERSION} -s -w"

.PHONY: all style format build test vet tarball linux-amd64

all: clean linux-amd64 darwin-amd64

clean:
@echo "Cleaning binaries dir ${BIN_DIR}"
@rm -rf ${BIN_DIR}/ 2> /dev/null

linux-amd64:
@echo "Building linux/amd64 binaries in ${BIN_DIR}"
@mkdir -p ${BIN_DIR}
@$(foreach pkg,$(pkgs),GOOS=linux GOARCH=amd64 go build -ldflags ${LDFLAGS} -o ${BIN_DIR}/$(pkg)_linux_amd64 ./;)

linux-386:
@echo "Building linux/386 binaries in ${BIN_DIR}"
@mkdir -p ${BIN_DIR}
@$(foreach pkg,$(pkgs),GOOS=linux GOARCH=386 go build -ldflags ${LDFLAGS} -o ${BIN_DIR}/$(pkg)_linux_386 ./;)

darwin-amd64:
@echo "Building darwin/amd64 binaries in ${BIN_DIR}"
@mkdir -p ${BIN_DIR}
@$(foreach pkg,$(pkgs),GOOS=darwin GOARCH=amd64 go build -ldflags ${LDFLAGS} -o ${BIN_DIR}/$(pkg)_darwin_amd64 ./;)

style:
@echo ">> checking code style"
@! gofmt -d $(shell find . -path ./vendor -prune -o -name '*.go' -print) | grep '^'

test:
@echo ">> running tests"
@./runtests.sh

format:
@echo ">> formatting code"
@$(GO) fmt $(pkgs)

vet:
@echo ">> vetting code"
@$(GO) vet $(pkgs)

22 changes: 19 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ var (
progress = app.Flag("show-progressbar", "Show progress bar").Default("true").Bool()
samples = app.Flag("max-fk-samples", "Maximum number of samples for foreign keys fields").Default("100").Int64()
factor = app.Flag("fk-samples-factor", "Percentage used to get random samples for foreign keys fields").Default("0.3").Float64()
version = app.Flag("version", "Show version and exit").Bool()
//
schema = app.Arg("database", "Database").Required().String()
tableName = app.Arg("table", "Table").Required().String()
rows = app.Arg("rows", "Number of rows to insert").Required().Int()
schema = app.Arg("database", "Database").String()
tableName = app.Arg("table", "Table").String()
rows = app.Arg("rows", "Number of rows to insert").Int()

validFunctions = []string{"int", "string", "date", "date_in_range"}
maxValues = map[string]int64{
Expand All @@ -51,6 +52,12 @@ var (
"double": 0x7FFFFFFF,
"bigint": 0x7FFFFFFFFFFFFFFF,
}

Version = "0.0.0."
Commit = "<sha1>"
Branch = "branch-name"
Build = "2017-01-01"
GoVersion = "1.9.2"
)

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

if *version {
fmt.Printf("Version : %s\n", Version)
fmt.Printf("Commit : %s\n", Commit)
fmt.Printf("Branch : %s\n", Branch)
fmt.Printf("Build : %s\n", Build)
fmt.Printf("Go version: %s\n", GoVersion)
return
}

address := *host
net := "unix"
if address != "localhost" {
Expand Down

0 comments on commit 67b1962

Please sign in to comment.