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