implemented version command
Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
parent
b0b16a2f2b
commit
2099381abd
@ -39,6 +39,7 @@ func init() {
|
|||||||
plan.Cmd,
|
plan.Cmd,
|
||||||
input.Cmd,
|
input.Cmd,
|
||||||
output.Cmd,
|
output.Cmd,
|
||||||
|
versionCmd,
|
||||||
)
|
)
|
||||||
|
|
||||||
if err := viper.BindPFlags(rootCmd.PersistentFlags()); err != nil {
|
if err := viper.BindPFlags(rootCmd.PersistentFlags()); err != nil {
|
||||||
|
35
cmd/dagger/cmd/version.go
Normal file
35
cmd/dagger/cmd/version.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"runtime"
|
||||||
|
"runtime/debug"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
defaultVersion = "devel"
|
||||||
|
)
|
||||||
|
|
||||||
|
// set by goreleaser or other builder using
|
||||||
|
// -ldflags='-X dagger.io/go/cmd/dagger/cmd.version=<version>'
|
||||||
|
var (
|
||||||
|
version = defaultVersion
|
||||||
|
)
|
||||||
|
|
||||||
|
var versionCmd = &cobra.Command{
|
||||||
|
Use: "version",
|
||||||
|
Short: "Print dagger version",
|
||||||
|
Args: cobra.NoArgs,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
if bi, ok := debug.ReadBuildInfo(); ok && version == defaultVersion {
|
||||||
|
// No specific version provided via version
|
||||||
|
version = bi.Main.Version
|
||||||
|
}
|
||||||
|
fmt.Printf("dagger version %v %s/%s\n",
|
||||||
|
version,
|
||||||
|
runtime.GOOS, runtime.GOARCH,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
}
|
Reference in New Issue
Block a user