diff --git a/release.sh b/release.sh index 990ca66..23b01ae 100755 --- a/release.sh +++ b/release.sh @@ -3,7 +3,7 @@ set -e VERSION=$(git describe --tags --dirty) GO_BUILD_CMD="go build -a -installsuffix cgo" -GO_BUILD_LDFLAGS="-s -w" +GO_BUILD_LDFLAGS="-s -w -X main.version=$VERSION" BUILD_PLATFORMS="linux darwin" BUILD_ARCHS="amd64" diff --git a/yaml2json.go b/yaml2json.go index 7aa8e24..67b04cb 100644 --- a/yaml2json.go +++ b/yaml2json.go @@ -4,11 +4,26 @@ import ( "github.com/go-yaml/yaml" "encoding/json" + "flag" "fmt" "log" + "os" +) + +var ( + showVersion = flag.Bool("version", false, "show version and exit") + url = "https://github.com/wakeful/yaml2json" + version = "dev" ) func main() { + flag.Parse() + + if *showVersion { + fmt.Printf("yaml2json\n url: %s\n version: %s\n", url, version) + os.Exit(2) + } + input, err := readInput() if err != nil {