Skip to content

Commit

Permalink
switch to small change and remove added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jackgopack4 committed Sep 23, 2024
1 parent 65f4612 commit ce1313f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 144 deletions.
2 changes: 1 addition & 1 deletion cmd/builder/internal/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ configuration is provided, ocb will generate a default Collector.
return nil, err
}
// version of this binary
cmd.AddCommand(versionCommand(binVersion))
cmd.AddCommand(versionCommand())

return cmd, nil
}
Expand Down
26 changes: 6 additions & 20 deletions cmd/builder/internal/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,20 @@ var (
version = ""
)

type debugReadBuildInfoFunc func() (info *debug.BuildInfo, ok bool)
type binVersionFunc func(fn debugReadBuildInfoFunc) (string, error)

// binVersion returns the version of the binary.
// If the version is not set, it attempts to read the build information.
// Returns an error if the build information cannot be read.
func binVersion(fn debugReadBuildInfoFunc) (string, error) {
if version != "" {
return version, nil
}
info, ok := fn()
if !ok {
return "", fmt.Errorf("failed to read build info")
func init() {
// the second returned value is a boolean, which is true if the binaries are built with module support.
if version == "" {
info, _ := debug.ReadBuildInfo()
version = info.Main.Version
}
return info.Main.Version, nil
}

func versionCommand(fn binVersionFunc) *cobra.Command {
var err error
func versionCommand() *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "Version of ocb",
Long: "Prints the version of the ocb binary",
RunE: func(cmd *cobra.Command, _ []string) error {
version, err = fn(debug.ReadBuildInfo)
if err != nil {
return err
}
cmd.Println(fmt.Sprintf("%s version %s", cmd.Parent().Name(), version))
return nil
},
Expand Down
123 changes: 0 additions & 123 deletions cmd/builder/internal/version_test.go

This file was deleted.

0 comments on commit ce1313f

Please sign in to comment.