File tree Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -7,13 +7,19 @@ import (
77 "path/filepath"
88)
99
10+ var version = flag .Bool ("version" , false , "print version information and exit" )
1011var list = flag .Bool ("list" , false , "list mode" )
1112var host = flag .String ("host" , "" , "host mode" )
1213
1314func main () {
1415 flag .Parse ()
1516 file := flag .Arg (0 )
1617
18+ if * version == true {
19+ fmt .Printf ("%s version %d\n " , os .Args [0 ], versionInfo ())
20+ return
21+ }
22+
1723 if file == "" {
1824 fmt .Printf ("Usage: %s [options] path\n " , os .Args [0 ])
1925 os .Exit (1 )
Original file line number Diff line number Diff line change 1+ package main
2+
3+ // Deliberately uninitialized. See below.
4+ var build_version string
5+
6+ // versionInfo returns a string containing the version information of the
7+ // current build. It's empty by default, but can be included as part of the
8+ // build process by setting the main.build_version variable.
9+ func versionInfo () string {
10+ if build_version != "" {
11+ return build_version
12+ } else {
13+ return "unknown"
14+ }
15+ }
Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "github.com/stretchr/testify/assert"
5+ "testing"
6+ )
7+
8+ func TestVersionInfo (t * testing.T ) {
9+ assert .Equal (t , "unknown" , versionInfo ())
10+
11+ build_version = "vXYZ"
12+ assert .Equal (t , "vXYZ" , versionInfo ())
13+ }
You can’t perform that action at this time.
0 commit comments