Merge branch 'add_version_flag' of asdf/gfu into master

This commit is contained in:
Sloom Sloum Sluom IV 2019-09-24 23:26:12 -04:00 committed by Gitea
commit b0a6e0842a
4 changed files with 44 additions and 2 deletions

View File

@ -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.

1
VERSION Normal file
View File

@ -0,0 +1 @@
0.1

12
main.go
View File

@ -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)

29
makefile Normal file
View File

@ -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