From 67b19620a215cafa3774cb51e9aecd09729b325c Mon Sep 17 00:00:00 2001 From: Carlos Salguero Date: Mon, 27 Nov 2017 08:24:29 -0300 Subject: [PATCH] Added Makefile, .gitignore, deps and --version --- .gitignore | 2 ++ Gopkg.lock | 20 ++++++++++++++++---- Gopkg.toml | 8 ++++++++ Makefile | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ main.go | 22 +++++++++++++++++++--- 5 files changed, 98 insertions(+), 7 deletions(-) create mode 100644 .gitignore create mode 100644 Makefile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0afc735 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +random_data_load* +vendor/ diff --git a/Gopkg.lock b/Gopkg.lock index 3adacd7..73baf01 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -37,6 +37,12 @@ packages = [".","util/strutil"] revision = "d0567a9d84a1c40dd7568115ea66f4887bf57b33" +[[projects]] + branch = "master" + name = "github.com/hashicorp/go-version" + packages = ["."] + revision = "fc61389e27c71d120f87031ca8c88a3428f372dd" + [[projects]] branch = "master" name = "github.com/icrowley/fake" @@ -58,14 +64,20 @@ [[projects]] name = "github.com/mattn/go-isatty" packages = ["."] - revision = "fc9e8d8ef48496124e79ae0df75490096eccf6fe" - version = "v0.0.2" + revision = "0360b2af4f38e8d38c7fce2a9f4e702702d73a39" + version = "v0.0.3" + +[[projects]] + name = "github.com/pkg/errors" + packages = ["."] + revision = "645ef00459ed84a119197bfb8d8205042c6df63d" + version = "v0.8.0" [[projects]] branch = "master" name = "golang.org/x/sys" packages = ["unix"] - revision = "429f518978ab01db8bb6f44b66785088e7fba58b" + revision = "4ff8c001ce4cc464e644b922325097228fce14d8" [[projects]] name = "gopkg.in/alecthomas/kingpin.v2" @@ -76,6 +88,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "d645838ba798f7970eaf76c79564d3f61471897704f70d252233151f3f3f1f58" + inputs-digest = "30675f913c9b84e5dee77da604a31e520958e00dc150b871961f2e333f416db9" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 7ba531c..4c08b4e 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -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" @@ -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" diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4782c40 --- /dev/null +++ b/Makefile @@ -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) + diff --git a/main.go b/main.go index c9146da..3883c22 100644 --- a/main.go +++ b/main.go @@ -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{ @@ -51,6 +52,12 @@ var ( "double": 0x7FFFFFFF, "bigint": 0x7FFFFFFFFFFFFFFF, } + + Version = "0.0.0." + Commit = "" + Branch = "branch-name" + Build = "2017-01-01" + GoVersion = "1.9.2" ) type insertValues []getters.Getter @@ -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" {