github.com/sudo-bmitch/version-bump@v0.0.0-20240503123857-70b0e3f646dd/internal/version/version.go (about)

     1  // Package version returns details on the Go and Git repo used in the build
     2  package version
     3  
     4  import (
     5  	"bytes"
     6  	"fmt"
     7  	"text/tabwriter"
     8  )
     9  
    10  const (
    11  	stateClean    = "clean"
    12  	stateDirty    = "dirty"
    13  	unknown       = "unknown"
    14  	biVCSDate     = "vcs.time"
    15  	biVCSCommit   = "vcs.revision"
    16  	biVCSModified = "vcs.modified"
    17  )
    18  
    19  func (i Info) MarshalPretty() ([]byte, error) {
    20  	buf := &bytes.Buffer{}
    21  	tw := tabwriter.NewWriter(buf, 0, 0, 1, ' ', 0)
    22  	fmt.Fprintf(tw, "VCSRef:\t%s\n", i.VCSRef)
    23  	fmt.Fprintf(tw, "VCSCommit:\t%s\n", i.VCSCommit)
    24  	fmt.Fprintf(tw, "VCSState:\t%s\n", i.VCSState)
    25  	fmt.Fprintf(tw, "VCSDate:\t%s\n", i.VCSDate)
    26  	fmt.Fprintf(tw, "Platform:\t%s\n", i.Platform)
    27  	fmt.Fprintf(tw, "GoVer:\t%s\n", i.GoVer)
    28  	fmt.Fprintf(tw, "GoCompiler:\t%s\n", i.GoCompiler)
    29  	tw.Flush()
    30  	return buf.Bytes(), nil
    31  }