diff --git a/README.md b/README.md index d5042ea..8600d00 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ spanner: --directed-read= Directed read option (replica_location:replica_type). The replicat_type is optional and either READ_ONLY or READ_WRITE --skip-tls-verify Insecurely skip TLS verify --proto-descriptor-file= Path of a file that contains a protobuf-serialized google.protobuf.FileDescriptorSet message to use in this invocation. + --version Show version of spanner-cli Help Options: -h, --help Show this help message diff --git a/main.go b/main.go index 1224c6b..0988cf6 100644 --- a/main.go +++ b/main.go @@ -23,6 +23,7 @@ import ( "os" "os/user" "path/filepath" + "runtime/debug" pb "cloud.google.com/go/spanner/apiv1/spannerpb" flags "github.com/jessevdk/go-flags" @@ -49,6 +50,7 @@ type spannerOptions struct { 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"` SkipTLSVerify bool `long:"skip-tls-verify" description:"Insecurely skip TLS verify"` 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."` + Version bool `long:"version" description:"Show version of spanner-cli"` } func main() { @@ -64,6 +66,11 @@ func main() { exitf("Invalid options\n") } + if gopts.Spanner.Version { + fmt.Fprintf(os.Stdout, "%s\n", versionInfo()) + os.Exit(0) + } + opts := gopts.Spanner if opts.ProjectId == "" || opts.InstanceId == "" || opts.DatabaseId == "" { exitf("Missing parameters: -p, -i, -d are required\n") @@ -197,3 +204,11 @@ func readStdin() (string, error) { return "", nil } } + +func versionInfo() string { + info, ok := debug.ReadBuildInfo() + if !ok { + return "(devel)" + } + return info.Main.Version +}