github.com/r3labs/libcompose@v0.4.1-0.20171123133234-495fe0619cc3/cli/app/version.go (about)

     1  package app
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"runtime"
     7  	"text/template"
     8  
     9  	"github.com/r3labs/libcompose/version"
    10  	"github.com/sirupsen/logrus"
    11  	"github.com/urfave/cli"
    12  )
    13  
    14  var versionTemplate = `Version:      {{.Version}} ({{.GitCommit}})
    15  Go version:   {{.GoVersion}}
    16  Built:        {{.BuildTime}}
    17  OS/Arch:      {{.Os}}/{{.Arch}}`
    18  
    19  // Version prints the libcompose version number and additionnal informations.
    20  func Version(c *cli.Context) error {
    21  	if c.Bool("short") {
    22  		fmt.Println(version.VERSION)
    23  		return nil
    24  	}
    25  
    26  	tmpl, err := template.New("").Parse(versionTemplate)
    27  	if err != nil {
    28  		logrus.Fatal(err)
    29  	}
    30  
    31  	v := struct {
    32  		Version   string
    33  		GitCommit string
    34  		GoVersion string
    35  		BuildTime string
    36  		Os        string
    37  		Arch      string
    38  	}{
    39  		Version:   version.VERSION,
    40  		GitCommit: version.GITCOMMIT,
    41  		GoVersion: runtime.Version(),
    42  		BuildTime: version.BUILDTIME,
    43  		Os:        runtime.GOOS,
    44  		Arch:      runtime.GOARCH,
    45  	}
    46  
    47  	if err := tmpl.Execute(os.Stdout, v); err != nil {
    48  		logrus.Fatal(err)
    49  	}
    50  	fmt.Printf("\n")
    51  	return nil
    52  }