Added -v flag and makefile for application version
This commit is contained in:
parent
56173fb6d4
commit
94835f416a
|
@ -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.
|
||||
|
|
12
main.go
12
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)
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
BINARY := gfu
|
||||
PKGS := $(shell go list ./... |grep -v /vendor)
|
||||
VERSION := $(shell git describe --tags)
|
||||
BUILD := $(shell date -Iminutes)
|
||||
|
||||
LDFLAGS := -ldflags "-s -X main.version=${VERSION} -X main.build=${BUILD}"
|
||||
#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
|
||||
|
||||
build:
|
||||
go build ${LDFLAGS} -o ${BINARY}
|
||||
|
||||
.PHONY: install
|
||||
install:
|
||||
go install ${LDFLAGS}
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
go clean
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
go test $(PKGS)
|
||||
|
||||
|
Loading…
Reference in New Issue