Skip to content

Commit

Permalink
Merge pull request #107 from shuheiktgw/use_build_info
Browse files Browse the repository at this point in the history
Use build info to retrieve version information
  • Loading branch information
kazegusuri committed Nov 17, 2022
2 parents 6499e10 + a396bd7 commit a7f4d05
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
18 changes: 16 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"fmt"
"os"
pathpkg "path"
"runtime/debug"
"strings"

"cloud.google.com/go/spanner"
Expand All @@ -44,7 +45,7 @@ const (
`
)

var version = "dev"
var version string

var (
rootOpts = internal.ArgType{}
Expand Down Expand Up @@ -105,7 +106,7 @@ var (
},
SilenceUsage: true,
SilenceErrors: true,
Version: version,
Version: versionInfo(),
}
)

Expand Down Expand Up @@ -230,3 +231,16 @@ func connectSpanner(args *internal.ArgType) (*spanner.Client, error) {

return spannerClient, nil
}

func versionInfo() string {
if version != "" {
return version
}

// For those who "go install" yo
info, ok := debug.ReadBuildInfo()
if !ok {
return "(devel)"
}
return info.Main.Version
}
18 changes: 16 additions & 2 deletions v2/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package cmd

import (
"runtime/debug"
"strings"

"github.com/spf13/cobra"
Expand All @@ -36,7 +37,7 @@ const (
`
)

var version = "dev"
var version string

var (
rootCmd = &cobra.Command{
Expand All @@ -49,10 +50,23 @@ var (
RunE: nil,
SilenceUsage: true,
SilenceErrors: true,
Version: version,
Version: versionInfo(),
}
)

func Execute() error {
return rootCmd.Execute()
}

func versionInfo() string {
if version != "" {
return version
}

// For those who "go install" yo
info, ok := debug.ReadBuildInfo()
if !ok {
return "(devel)"
}
return info.Main.Version
}

0 comments on commit a7f4d05

Please sign in to comment.