feat: add version data and display

This commit is contained in:
Emmanuel BENOîT 2024-07-26 13:06:45 +02:00
parent 939a87cb56
commit cf1e599be8
Signed by: Emmanuel BENOîT
SSH key fingerprint: SHA256:l7PFUUF5TCDsvYeQC9OnTNz08dFY7Fvf4Hv3neIqYpg
2 changed files with 36 additions and 1 deletions

10
main.go
View file

@ -1,6 +1,7 @@
package main
import (
"fmt"
"os"
"github.com/karrick/golf"
@ -41,7 +42,7 @@ type (
// Parse command line options.
func parseCommandLine() tCliFlags {
var help bool
var help, version bool
flags := tCliFlags{}
golf.StringVarP(&flags.cfgFile, 'c', "config", "/etc/fetch-certificates.yml",
@ -70,10 +71,17 @@ func parseCommandLine() tCliFlags {
golf.StringVarP(&flags.selector, 'u', "update", "*",
"LDAP DN of the certificate to select, or '*' to update all "+
"certificates.")
golf.BoolVarP(&version, 'v', "version", false, "Display version and exit.")
golf.Parse()
if version || help {
fmt.Println("fetchcert", versionString())
}
if help {
fmt.Println()
golf.Usage()
}
if version || help {
os.Exit(0)
}
return flags

27
version.go Normal file
View file

@ -0,0 +1,27 @@
package main
import "fmt"
var (
version = ""
commit = "unknown"
status = ""
target = "unknown/unknown"
)
func versionString() string {
var schar, ver string
if status == "dirty" {
schar = "*"
} else {
schar = ""
}
if version == "" {
ver = "development version"
} else {
ver = version
}
return fmt.Sprintf("%s (%s%s) %s", ver, commit, schar, target)
}