@@ -8,24 +8,53 @@ import (
8
8
"net/http"
9
9
"os"
10
10
"path"
11
+ "runtime"
12
+ "time"
11
13
"unicode"
12
14
13
15
"github.com/pkg/errors"
14
16
"github.com/smallstep/certificates/authority"
15
17
"github.com/smallstep/certificates/ca"
16
18
)
17
19
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
+
18
28
func usage () {
19
29
fmt .Fprintf (os .Stderr , "Usage: %s [options] <config.json>\n \n " , path .Base (os .Args [0 ]))
20
30
flag .PrintDefaults ()
21
31
}
22
32
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
+
23
45
func main () {
46
+ var version bool
24
47
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" )
26
50
flag .Usage = usage
27
51
flag .Parse ()
28
52
53
+ if version {
54
+ printVersion ()
55
+ os .Exit (0 )
56
+ }
57
+
29
58
if flag .NArg () != 1 {
30
59
flag .Usage ()
31
60
os .Exit (1 )
0 commit comments