github.com/pluralsh/plural-cli@v0.9.5/cmd/plural/version.go (about)

     1  package plural
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"runtime"
     7  	"strings"
     8  
     9  	"golang.org/x/mod/semver"
    10  
    11  	"github.com/pluralsh/plural-cli/pkg/utils"
    12  	"github.com/urfave/cli"
    13  )
    14  
    15  const (
    16  	versionPlaceholder = "dev"
    17  )
    18  
    19  var (
    20  	Version = versionPlaceholder
    21  	Commit  = ""
    22  	Date    = ""
    23  )
    24  
    25  func versionValid(vsn string) bool {
    26  	current := Version
    27  	if !strings.HasPrefix(current, "v") {
    28  		current = fmt.Sprintf("v%s", current)
    29  	}
    30  	return semver.Compare(vsn, current) <= 0
    31  }
    32  
    33  func checkRecency() error {
    34  	if os.Getenv("CLOUD_SHELL") == "1" || os.Getenv("PLURAL_CONSOLE") == "1" {
    35  		return nil
    36  	}
    37  
    38  	if Version == versionPlaceholder || strings.Contains(Version, "-") {
    39  		utils.Warn("\nThis is a development version, which can be significantly different from official releases")
    40  		utils.Warn("\nYou can download latest release from https://github.com/pluralsh/plural-cli/releases/latest\n")
    41  		return nil
    42  	}
    43  
    44  	utils.CheckLatestVersion(Version)
    45  
    46  	return nil
    47  }
    48  
    49  func versionInfo(c *cli.Context) error {
    50  	fmt.Println("PLURAL CLI:")
    51  	fmt.Printf("   version\t%s\n", Version)
    52  	fmt.Printf("   git commit\t%s\n", Commit)
    53  	fmt.Printf("   compiled at\t%s\n", Date)
    54  	fmt.Printf("   os/arch\t%s/%s\n", runtime.GOOS, runtime.GOARCH)
    55  
    56  	return checkRecency()
    57  }