Skip to content

Commit

Permalink
Add version flag and build information
Browse files Browse the repository at this point in the history
  • Loading branch information
labkode committed Jan 22, 2017
1 parent ed98755 commit feac87b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
7 changes: 5 additions & 2 deletions cmd/clawiod/build.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env bash
#
# ClawIO build script. Add build variables to compiled binary.
#
# Usage:
# # Usage:
#
# $ ./build.bash [output_filename] [git_repo]
#
Expand Down Expand Up @@ -46,6 +45,10 @@ commit_name="${pkg}.gitCommit"
commit_value="$(git -C "${git_repo}" rev-parse --short HEAD)"
ldflags+=("-X" "\"${commit_name}=${commit_value}\"")

# Application name
app_name="${pkg}.appName"
ldflags+=("-X" "\"${app_name}=${output_filename}\"")


releases_dir=${git_repo}/releases
rm -rf ${releases_dir}
Expand Down
28 changes: 27 additions & 1 deletion cmd/clawiod/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,31 @@ import (
"strings"
)

var flagConfigurationSource string
var (
flagConfigurationSource string
flagVersion bool
)

// Build information obtained with the help of -ldflags
var (
appName string
buildDate string // date -u
gitTag string // git describe --exact-match HEAD
gitNearestTag string // git describe --abbrev=0 --tags HEAD
gitCommit string // git rev-parse HEAD
)

func init() {
flag.StringVar(&flagConfigurationSource, "conf", "file:clawiod.conf", "Configuration source where to obtain the configuration")
flag.BoolVar(&flagVersion, "version", false, "Show version")
flag.Parse()
}

func main() {
if flagVersion {
handleVersion()
}

configurationSource, err := getConfigurationSource(flagConfigurationSource)
if err != nil {
fmt.Println(err)
Expand Down Expand Up @@ -109,6 +126,15 @@ func main() {
}
}

func handleVersion() {
// if gitTag is not empty we are on release build
if gitTag != "" {
fmt.Printf("%s %s commit:%s release-build\n", appName, gitNearestTag, gitCommit)
os.Exit(0)
}
fmt.Printf("%s %s commit:%s dev-build\n", appName, gitNearestTag, gitCommit)
os.Exit(0)
}
func getUserDriver(config root.Configuration) (root.UserDriver, error) {
switch config.GetUserDriver() {
case "memuserdriver":
Expand Down

0 comments on commit feac87b

Please sign in to comment.