diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..2f45361 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.2 \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..0b7d4ea --- /dev/null +++ b/build.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env sh + +# shellcheck disable=SC2155 +export GIT_COMMIT=$(git rev-list -1 HEAD) +CANONICAL_VERSION=$(cat ./VERSION) +VERSION_STRING="$CANONICAL_VERSION ($GIT_COMMIT)" + +go mod vendor +go mod tidy +go build -o build/gostations -ldflags "-X main.version=$VERSION_STRING" diff --git a/stations.go b/stations.go index 5955789..f4d8877 100644 --- a/stations.go +++ b/stations.go @@ -6,6 +6,12 @@ import ( "os" ) +var version float32 + +func showVersion(){ + fmt.Println(version) +} + func precheck(){ if !isInstalled(player()){ fmt.Printf("%s is either not installed, or not on your $PATH. Cannot continue.\n", player()) @@ -22,11 +28,12 @@ func main(){ state string tags string notok bool + version bool ) flag.Usage = func() { fmt.Printf("Usage: \n") fmt.Printf(" gostations ") - fmt.Printf(" [-n \"name\"] [-c \"home country\"] [-s \"home state\"] [-t \"ordered,tag,list\"] [-x]\n") + fmt.Printf(" [-n \"name\"] [-c \"home country\"] [-s \"home state\"] [-t \"ordered,tag,list\"] [-x] [-v]\n") flag.PrintDefaults() fmt.Printf(" -h (or none)\n") fmt.Printf("\tThis help message\n") @@ -36,12 +43,19 @@ func main(){ flag.StringVar(&state, "s", "", "Home state (if in the United States).") flag.StringVar(&tags, "t", "", "Tag (or comma-separated tag list)") flag.BoolVar(¬ok, "x", false,"If toggled, will show stations that are down") + flag.BoolVar(&version, "v", false, "Show version.") flag.Parse() if argCount == 0 { flag.Usage() os.Exit(0) } + + if version { + showVersion() + os.Exit(0) + } + precheck() stations, _ := StationSearch(name, country, state, tags, notok)