chore: add support for build automation #5
2 changed files with 36 additions and 1 deletions
10
main.go
10
main.go
|
@ -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
27
version.go
Normal 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)
|
||||
}
|
Loading…
Reference in a new issue