| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package internal // import "go.opentelemetry.io/collector/cmd/builder/internal" |
| 5 |
|
| 6 |
import ( |
| 7 |
"fmt" |
| 8 |
"runtime/debug" |
| 9 |
|
| 10 |
"github.com/spf13/cobra" |
| 11 |
) |
| 12 |
|
| 13 |
var version = "" |
| 14 |
|
| 15 |
func init() { |
| 16 |
// the second returned value is a boolean, which is true if the binaries are built with module support. |
| 17 |
if version != "" { |
| 18 |
return |
| 19 |
} |
| 20 |
info, ok := debug.ReadBuildInfo() |
| 21 |
if ok { |
| 22 |
version = info.Main.Version |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
func versionCommand() *cobra.Command { |
| 27 |
return &cobra.Command{ |
| 28 |
Use: "version", |
| 29 |
Short: "Version of ocb", |
| 30 |
Long: "Prints the version of the ocb binary", |
| 31 |
RunE: func(cmd *cobra.Command, _ []string) error { |
| 32 |
cmd.Println(fmt.Sprintf("%s version %s", cmd.Parent().Name(), version)) |
| 33 |
return nil |
| 34 |
}, |
| 35 |
} |
| 36 |
} |