Skip to content

Commit

Permalink
feat: add version (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
maaslalani authored Apr 3, 2024
1 parent 974eec2 commit 1899c76
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"
"path/filepath"
"runtime/debug"
"strings"

"github.com/alecthomas/chroma/v2"
Expand All @@ -28,7 +29,19 @@ const (
defaultLineHeight = 1.2
)

var (
// Version contains the application version number. It's set via ldflags
// when building.
Version = ""

// CommitSHA contains the SHA of the commit that this application was built
// against. It's set via ldflags when building.
CommitSHA = ""
)

func main() {
const shaLen = 7

var (
input string
err error
Expand All @@ -46,6 +59,27 @@ func main() {
printErrorFatal("Invalid Usage", err)
}

if len(ctx.Args) > 0 {
switch ctx.Args[0] {

case "version":
if Version == "" {
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Sum != "" {
Version = info.Main.Version
} else {
Version = "unknown (built from source)"
}
}
version := fmt.Sprintf("freeze version %s", Version)
if len(CommitSHA) >= shaLen {
version += " (" + CommitSHA[:shaLen] + ")"
}

fmt.Println(version)
os.Exit(0)
}
}

// Copy the pty output to buffer
if config.Execute != "" {
input, err = executeCommand(config)
Expand Down

0 comments on commit 1899c76

Please sign in to comment.