1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
package main
import (
"fmt"
"runtime"
"strconv"
"time"
cniversion "github.com/containernetworking/cni/pkg/version"
"github.com/containers/buildah"
iversion "github.com/containers/image/v5/version"
ispecs "github.com/opencontainers/image-spec/specs-go"
rspecs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/spf13/cobra"
)
//Overwritten at build time
var (
GitCommit string
buildInfo string
cniVersion string
)
//Function to get and print info for version command
func versionCmd(c *cobra.Command, args []string) error {
var err error
buildTime := int64(0)
if buildInfo != "" {
//converting unix time from string to int64
buildTime, err = strconv.ParseInt(buildInfo, 10, 64)
if err != nil {
return err
}
}
fmt.Println("Version: ", buildah.Version)
fmt.Println("Go Version: ", runtime.Version())
fmt.Println("Image Spec: ", ispecs.Version)
fmt.Println("Runtime Spec: ", rspecs.Version)
fmt.Println("CNI Spec: ", cniversion.Current())
fmt.Println("libcni Version: ", cniVersion)
fmt.Println("image Version: ", iversion.Version)
fmt.Println("Git Commit: ", GitCommit)
//Prints out the build time in readable format
fmt.Println("Built: ", time.Unix(buildTime, 0).Format(time.ANSIC))
fmt.Println("OS/Arch: ", runtime.GOOS+"/"+runtime.GOARCH)
return nil
}
//cli command to print out the version info of buildah
var versionCommand = &cobra.Command{
Use: "version",
Short: "Display the Buildah version information",
Long: "Displays Buildah version information.",
RunE: versionCmd,
Args: cobra.NoArgs,
Example: `buildah version`,
}
func init() {
versionCommand.SetUsageTemplate(UsageTemplate())
rootCmd.AddCommand(versionCommand)
}
|