From 4ea8d82dd3ad4bcf62fa049d597990de32ea2d63 Mon Sep 17 00:00:00 2001 From: Ivan Krutov Date: Sat, 13 May 2017 13:10:16 +0300 Subject: [PATCH] Added automatic -version command (fixes #62) --- .travis.yml | 4 ++-- docs/cli-flags.adoc | 30 ++++++++++++++++++++++++++++++ docs/index.adoc | 1 + main.go | 14 ++++++++++++++ 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 docs/cli-flags.adoc diff --git a/.travis.yml b/.travis.yml index 50e5466..489bc2b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,8 +9,8 @@ services: script: - go test -race -coverprofile=coverage.txt -covermode=atomic -coverpkg . - - GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build - - gox -os "linux darwin" -arch "amd64" -output "dist/{{.Dir}}_{{.OS}}_{{.Arch}}" + - GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-X main.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.gitRevision=`git rev-parse HEAD`" + - gox -os "linux darwin" -arch "amd64" -output "dist/{{.Dir}}_{{.OS}}_{{.Arch}}" -ldflags "-X main.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.gitRevision=`git rev-parse HEAD`" before_install: - go get -u github.com/kardianos/govendor diff --git a/docs/cli-flags.adoc b/docs/cli-flags.adoc new file mode 100644 index 0000000..4153d57 --- /dev/null +++ b/docs/cli-flags.adoc @@ -0,0 +1,30 @@ +== Ggr CLI Flags + +The following flags are supported by ```ggr``` command: +``` + -listen string + host and port to listen to (default ":4444") + -quotaDir string + quota directory (default "quota") + -timeout duration + session creation timeout in time.Duration format, e.g. 300s or 500ms (default 5m0s) + -users string + htpasswd auth file path (default ".htpasswd") + -version + show version and exit +``` +For example: +``` +$ ./ggr -quotaDir /my/custom/quota/dir +``` +When using Ggr inside Docker container these flags are passed like the following: + + +[source,bash,subs="attributes+"] +---- +# docker run -d --name \ + ggr -v /etc/grid-router/:/etc/grid-router:ro \ + --net host aerokube/ggr:1.1.1 + -quotaDir /my/custom/quota/dir +---- + diff --git a/docs/index.adoc b/docs/index.adoc index 6698d21..a08a373 100644 --- a/docs/index.adoc +++ b/docs/index.adoc @@ -25,5 +25,6 @@ include::quota-files.adoc[leveloffset=+1] include::quota-reload.adoc[leveloffset=+1] include::how-it-works.adoc[leveloffset=+1] include::log-files.adoc[leveloffset=+1] +include::cli-flags.adoc[leveloffset=+1] include::contributing.adoc[] diff --git a/main.go b/main.go index 6a51a29..8279bbf 100644 --- a/main.go +++ b/main.go @@ -23,6 +23,10 @@ var ( startTime = time.Now() lastReloadTime = time.Now() + + version bool + gitRevision string = "HEAD" + buildStamp string = "unknown" ) func loadQuotaFiles(quotaDir string) error { @@ -61,12 +65,22 @@ func updateQuota(quotaName string, browsers Browsers) { lastReloadTime = time.Now() } +func showVersion() { + fmt.Printf("Git Revision: %s\n", gitRevision) + fmt.Printf("UTC Build Time: %s\n", buildStamp) +} + func init() { flag.StringVar(&listen, "listen", ":4444", "host and port to listen to") flag.StringVar("aDir, "quotaDir", "quota", "quota directory") flag.StringVar(&users, "users", ".htpasswd", "htpasswd auth file path") flag.DurationVar(&timeout, "timeout", 300*time.Second, "session creation timeout in time.Duration format, e.g. 300s or 500ms") + flag.BoolVar(&version, "version", false, "show version and exit") flag.Parse() + if version { + showVersion() + os.Exit(0) + } log.Printf("Users file is [%s]\n", users) if err := loadQuotaFiles(quotaDir); err != nil { log.Fatalf("%v\n", err)