Skip to content

Commit a09f4ef

Browse files
authored
Add cli flag --version to show version of spanner-cli (#198)
1 parent 30bae18 commit a09f4ef

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ spanner:
5353
--directed-read= Directed read option (replica_location:replica_type). The replicat_type is optional and either READ_ONLY or READ_WRITE
5454
--skip-tls-verify Insecurely skip TLS verify
5555
--proto-descriptor-file= Path of a file that contains a protobuf-serialized google.protobuf.FileDescriptorSet message to use in this invocation.
56+
--version Show version of spanner-cli
5657
5758
Help Options:
5859
-h, --help Show this help message

main.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"os"
2424
"os/user"
2525
"path/filepath"
26+
"runtime/debug"
2627

2728
pb "cloud.google.com/go/spanner/apiv1/spannerpb"
2829
flags "github.com/jessevdk/go-flags"
@@ -49,6 +50,7 @@ type spannerOptions struct {
4950
DirectedRead string `long:"directed-read" description:"Directed read option (replica_location:replica_type). The replicat_type is optional and either READ_ONLY or READ_WRITE"`
5051
SkipTLSVerify bool `long:"skip-tls-verify" description:"Insecurely skip TLS verify"`
5152
ProtoDescriptorFile string `long:"proto-descriptor-file" description:"Path of a file that contains a protobuf-serialized google.protobuf.FileDescriptorSet message to use in this invocation."`
53+
Version bool `long:"version" description:"Show version of spanner-cli"`
5254
}
5355

5456
func main() {
@@ -64,6 +66,11 @@ func main() {
6466
exitf("Invalid options\n")
6567
}
6668

69+
if gopts.Spanner.Version {
70+
fmt.Fprintf(os.Stdout, "%s\n", versionInfo())
71+
os.Exit(0)
72+
}
73+
6774
opts := gopts.Spanner
6875
if opts.ProjectId == "" || opts.InstanceId == "" || opts.DatabaseId == "" {
6976
exitf("Missing parameters: -p, -i, -d are required\n")
@@ -197,3 +204,11 @@ func readStdin() (string, error) {
197204
return "", nil
198205
}
199206
}
207+
208+
func versionInfo() string {
209+
info, ok := debug.ReadBuildInfo()
210+
if !ok {
211+
return "(devel)"
212+
}
213+
return info.Main.Version
214+
}

0 commit comments

Comments
 (0)