add a version subcommand

fix #63
This commit is contained in:
ppom 2023-12-31 12:00:00 +01:00
parent b834e02755
commit f6f26f283e
3 changed files with 21 additions and 4 deletions

View file

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

View file

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

View file

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