Skip to content

Commit e0877a0

Browse files
committed
Add version flag to step-ca.
1 parent f8df470 commit e0877a0

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

cmd/step-ca/main.go

+30-1
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,53 @@ import (
88
"net/http"
99
"os"
1010
"path"
11+
"runtime"
12+
"time"
1113
"unicode"
1214

1315
"github.com/pkg/errors"
1416
"github.com/smallstep/certificates/authority"
1517
"github.com/smallstep/certificates/ca"
1618
)
1719

20+
// Version is set by an LDFLAG at build time representing the git tag or commit
21+
// for the current release
22+
var Version = "N/A"
23+
24+
// BuildTime is set by an LDFLAG at build time representing the timestamp at
25+
// the time of build
26+
var BuildTime = "N/A"
27+
1828
func usage() {
1929
fmt.Fprintf(os.Stderr, "Usage: %s [options] <config.json>\n\n", path.Base(os.Args[0]))
2030
flag.PrintDefaults()
2131
}
2232

33+
func printVersion() {
34+
version, buildTime := Version, BuildTime
35+
if version == "N/A" {
36+
version = "0000000-dev"
37+
}
38+
if buildTime == "N/A" {
39+
buildTime = time.Now().UTC().Format("2006-01-02 15:04 MST")
40+
}
41+
fmt.Printf("Smallstep CA/%s (%s/%s)\n", version, runtime.GOOS, runtime.GOARCH)
42+
fmt.Printf("Release Date: %s\n", buildTime)
43+
}
44+
2345
func main() {
46+
var version bool
2447
var configFile, passFile string
25-
flag.StringVar(&passFile, "password-file", "", "Path to file containing a password")
48+
flag.StringVar(&passFile, "password-file", "", "path to file containing a password")
49+
flag.BoolVar(&version, "version", false, "print version and exit")
2650
flag.Usage = usage
2751
flag.Parse()
2852

53+
if version {
54+
printVersion()
55+
os.Exit(0)
56+
}
57+
2958
if flag.NArg() != 1 {
3059
flag.Usage()
3160
os.Exit(1)

0 commit comments

Comments
 (0)