github.com/circl-dev/go-swagger@v0.31.0/cmd/swagger/commands/version.go (about)

     1  package commands
     2  
     3  import (
     4  	"fmt"
     5  	"runtime/debug"
     6  )
     7  
     8  var (
     9  	// Version for the swagger command
    10  	Version string
    11  	// Commit for the swagger command
    12  	Commit string
    13  )
    14  
    15  // PrintVersion the command
    16  type PrintVersion struct {
    17  }
    18  
    19  // Execute this command
    20  func (p *PrintVersion) Execute(args []string) error {
    21  	if Version == "" {
    22  		if info, available := debug.ReadBuildInfo(); available && info.Main.Version != "(devel)" {
    23  			// built from source, with module (e.g. go get)
    24  			fmt.Println("version:", info.Main.Version)
    25  			fmt.Println("commit:", fmt.Sprintf("(unknown, mod sum: %q)", info.Main.Sum))
    26  			return nil
    27  		}
    28  		// built from source, local repo
    29  		fmt.Println("dev")
    30  		return nil
    31  	}
    32  	// released version
    33  	fmt.Println("version:", Version)
    34  	fmt.Println("commit:", Commit)
    35  
    36  	return nil
    37  }