diff --git a/Makefile b/Makefile index cdd17c6..518b439 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ ip46tables: ip46tables.d/ip46tables.c gcc -static ip46tables.d/ip46tables.c -o ip46tables reaction: app/* reaction.go go.mod go.sum - CGO_ENABLED=0 go build -buildvcs=false . + CGO_ENABLED=0 go build -buildvcs=false -ldflags "-X main.version=`git tag --sort=v:refname | tail -n1` -X main.commit=`git rev-parse --short HEAD`" reaction.deb: reaction ip46tables chmod +x reaction ip46tables diff --git a/app/main.go b/app/main.go index b2ce309..3fc0a41 100644 --- a/app/main.go +++ b/app/main.go @@ -72,7 +72,11 @@ func basicUsage() { bold = "\033[1m" reset = "\033[0m" ) - fmt.Print(bold + `reaction start` + reset + ` + fmt.Print( + bold + `reaction help` + reset + ` + # print this help message + +` + bold + `reaction start` + reset + ` # start the daemon # options: @@ -106,6 +110,9 @@ func basicUsage() { ` + bold + `reaction test-regex` + reset + ` REGEX LINE # test REGEX against LINE cat FILE | ` + bold + `reaction test-regex` + reset + ` REGEX # test REGEX against each line of FILE +` + bold + `reaction version` + reset + ` + # print version information + see usage examples, service configurations and good practices on the ` + bold + `wiki` + reset + `: https://framagit.org/ppom/reaction-wiki `) @@ -114,7 +121,7 @@ on the ` + bold + `wiki` + reset + `: https://framagit.org/ppom/reaction-wiki //go:embed example.yml var exampleConf string -func Main() { +func Main(version, commit string) { if len(os.Args) <= 1 { logger.Fatalln("No argument provided. Try `reaction help`") basicUsage() @@ -125,6 +132,9 @@ func Main() { case "help", "-h", "-help", "--help": basicUsage() + case "version", "-v", "--version": + fmt.Printf("reaction version %v commit %v\n", commit, version) + case "example-conf": subCommandParse(f, 0) fmt.Print(exampleConf) diff --git a/reaction.go b/reaction.go index d3aa098..860a129 100644 --- a/reaction.go +++ b/reaction.go @@ -5,5 +5,12 @@ import ( ) func main() { - app.Main() + app.Main(version, commit) } + +var ( + // Must be passed when building + // go build -ldflags "-X app.commit XXX -X app.version XXX" + version string + commit string +)