diff --git a/README.md b/README.md index cc05a91..681f83f 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Assuming you have `go` installed, run the following: ``` git clone https://tildegit.org/sloum/gfu.git cd gfu -go install +make install ``` Assuming `go install` is set up to install to a place on your path, you should be able to execute `gfu` from the terminal: ``` @@ -29,7 +29,7 @@ gfu ``` #### Troubleshooting -If you run `gfu` and get `gfu: command not found`, try running `go build` from within the cloned repo. Then try: `./gfu`. If that works it means that Go does not install to your path. `go build` added an executable file to the repo directory. Move that file to somewhere on your path. I suggest `/usr/local/bin` on most systems, but that may be a matter of personal preference. +If you run `gfu` and get `gfu: command not found`, try running `make` from within the cloned repo. Then try: `./gfu`. If that works it means that Go does not install to your path. `make` added an executable file to the repo directory. Move that file to somewhere on your path. I suggest `/usr/local/bin` on most systems, but that may be a matter of personal preference. ### Downloading If you would prefer to download a binary for your system, rather than build from source, please visit the [gfu downloads](https://rawtext.club/~sloum/gfu.html#downloads) page. diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..49d5957 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1 diff --git a/main.go b/main.go index 995a609..d98a499 100644 --- a/main.go +++ b/main.go @@ -42,12 +42,19 @@ import ( "strings" ) +//version information, set by ldflags with some default fallbacks +var ( + version string = "not set" + build string = "not set" +) + //command line flag global variables var ( deconstructInfoTextLines bool header string footer string stdout bool + printVersion bool ) //regex global variable that identifies the format of gopher menu lines @@ -142,6 +149,7 @@ func init() { flag.StringVar(&header, "head", "", "Path to a file containing header content") flag.StringVar(&footer, "foot", "", "Path to a file containing footer content") flag.BoolVar(&stdout, "stdout", false, "Instead of writing changes to a file, return them to stdout") + flag.BoolVar(&printVersion, "v", false, "Output version information") } //PrintHelp produces a nice display message when the --help flag is used @@ -165,6 +173,10 @@ func main() { flag.Parse() args := flag.Args() + if printVersion { + fmt.Printf("gfu - gophermap format utility - version %s build %s\n", version, build) + os.Exit(0) + } if l := len(args); l != 1 { fmt.Fprintf(os.Stderr, "Incorrect number of arguments. Expected 1, got %d\n", l) os.Exit(1) diff --git a/makefile b/makefile new file mode 100644 index 0000000..ab16706 --- /dev/null +++ b/makefile @@ -0,0 +1,29 @@ +BINARY := gfu +PKGS := $(shell go list ./... |grep -v /vendor) + +# version checks git tags. if any errors, they are discarded, and the version is +# read from the VERSION file +VERSION := $(shell git describe --tags 2> /dev/null) +ifeq ($(VERSION),) + VERSION := $(shell cat VERSION) +endif +BUILD := $(shell date -Iminutes) + +#ldflags for versioning info: https://stackoverflow.com/questions/11354518/application-auto-build-versioning +#-s flag info: https://blog.spiralscout.com/using-w-and-s-flags-in-golang-97ae59b50e26 +LDFLAGS := -ldflags "-s -X main.version=${VERSION} -X main.build=${BUILD}" + +build: + go build ${LDFLAGS} -o ${BINARY} + +.PHONY: install +install: + go install ${LDFLAGS} + +.PHONY: uninstall +uninstall: + go clean -i + +.PHONY: clean +clean: + go clean