Skip to content

Commit

Permalink
Added version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
noborus committed Mar 15, 2023
1 parent 9197ff1 commit 4897e94
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BINARY_NAME := guesswidth
SRCS := $(shell git ls-files '*.go')
LDFLAGS := "-X main.version=$(shell git describe --tags --abbrev=0 --always) -X main.revision=$(shell git rev-parse --short HEAD)"
LDFLAGS := "-X github.com/noborus/guesswidth.version=$(shell git describe --tags --abbrev=0 --always) -X github.com/noborus/guesswidth.revision=$(shell git rev-parse --short HEAD)"

all: build

Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var rootCmd = &cobra.Command{
Short: "Guess the width of the column and split it",
Long: `Guess the width of the columns from the header and body,
split them, insert fences and output.`,
Version: guesswidth.Version(),
Run: func(cmd *cobra.Command, args []string) {
writeTable(args)
},
Expand Down
17 changes: 17 additions & 0 deletions guesswidth.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"bufio"
"fmt"
"io"
"runtime/debug"
"strings"
"unicode"

Expand Down Expand Up @@ -285,3 +286,19 @@ func debugCountPrint(line string, blanks []int) {
}
fmt.Println()
}

var (
version string
revision string
)

func Version() string {
if version != "" {
return version + " rev:" + revision
}
info, ok := debug.ReadBuildInfo()
if !ok {
return "(devel)"
}
return info.Main.Version
}

0 comments on commit 4897e94

Please sign in to comment.