Merge branch 'add_version_flag' of asdf/gfu into master
This commit is contained in:
commit
b0a6e0842a
|
@ -21,7 +21,7 @@ Assuming you have `go` installed, run the following:
|
||||||
```
|
```
|
||||||
git clone https://tildegit.org/sloum/gfu.git
|
git clone https://tildegit.org/sloum/gfu.git
|
||||||
cd gfu
|
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:
|
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
|
#### 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
|
### 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.
|
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"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//version information, set by ldflags with some default fallbacks
|
||||||
|
var (
|
||||||
|
version string = "not set"
|
||||||
|
build string = "not set"
|
||||||
|
)
|
||||||
|
|
||||||
//command line flag global variables
|
//command line flag global variables
|
||||||
var (
|
var (
|
||||||
deconstructInfoTextLines bool
|
deconstructInfoTextLines bool
|
||||||
header string
|
header string
|
||||||
footer string
|
footer string
|
||||||
stdout bool
|
stdout bool
|
||||||
|
printVersion bool
|
||||||
)
|
)
|
||||||
|
|
||||||
//regex global variable that identifies the format of gopher menu lines
|
//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(&header, "head", "", "Path to a file containing header content")
|
||||||
flag.StringVar(&footer, "foot", "", "Path to a file containing footer 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(&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
|
//PrintHelp produces a nice display message when the --help flag is used
|
||||||
|
@ -165,6 +173,10 @@ func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
args := flag.Args()
|
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 {
|
if l := len(args); l != 1 {
|
||||||
fmt.Fprintf(os.Stderr, "Incorrect number of arguments. Expected 1, got %d\n", l)
|
fmt.Fprintf(os.Stderr, "Incorrect number of arguments. Expected 1, got %d\n", l)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue