implemented version command

Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
Sam Alba 2021-04-29 14:27:30 -07:00
parent b0b16a2f2b
commit 2099381abd
2 changed files with 36 additions and 0 deletions

View File

@ -39,6 +39,7 @@ func init() {
plan.Cmd,
input.Cmd,
output.Cmd,
versionCmd,
)
if err := viper.BindPFlags(rootCmd.PersistentFlags()); err != nil {

35
cmd/dagger/cmd/version.go Normal file
View 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,
)
},
}