github.com/tonto/cli@v0.0.0-20180104210444-aec958fa47db/version.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/fnproject/cli/client"
     7  	fnclient "github.com/fnproject/fn_go/client/version"
     8  	"github.com/urfave/cli"
     9  )
    10  
    11  // Version of Fn CLI
    12  var Version = "0.4.36"
    13  
    14  func version() cli.Command {
    15  	return cli.Command{
    16  		Name:   "version",
    17  		Usage:  "displays cli and server versions",
    18  		Action: versionCMD,
    19  	}
    20  }
    21  
    22  func versionCMD(c *cli.Context) error {
    23  	t, reg := client.GetTransportAndRegistry()
    24  	// dirty hack, swagger paths live under /v1
    25  	// version is also there, but it shouldn't
    26  	// dropping base path to get appropriate URL for request eventually
    27  	t.BasePath = ""
    28  	fmt.Println("Client version: ", Version)
    29  	versionClient := fnclient.New(t, reg)
    30  	v, err := versionClient.GetVersion(nil)
    31  	if err != nil {
    32  		fmt.Println("Server version: ", "?")
    33  		return nil
    34  	}
    35  	fmt.Println("Server version: ", v.Payload.Version)
    36  	return nil
    37  }