chore: add support for build automation #5

Merged
Emmanuel BENOîT merged 10 commits from tseeker/fetchcert:20240726-build-automation into master 2024-07-26 14:07:47 +02:00
2 changed files with 36 additions and 1 deletions
Showing only changes of commit cf1e599be8 - Show all commits

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