Skip to content

Commit

Permalink
Add cli flag --version to show version of spanner-cli (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyu08 authored Dec 4, 2024
1 parent 30bae18 commit a09f4ef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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() {
Expand All @@ -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")
Expand Down Expand Up @@ -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
}

0 comments on commit a09f4ef

Please sign in to comment.