Skip to content

Commit

Permalink
add -version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
xrstf committed Aug 21, 2023
1 parent 5a50bba commit 23e0bd5
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,21 @@ import (
"path"
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"
"time"

"github.com/sirupsen/logrus"
)

// These variables get set by ldflags during compilation.
var (
BuildTag string
BuildCommit string
BuildDate string // RFC3339 format ("2006-01-02T15:04:05Z07:00")
)

// regular expressions
var (
now = time.Now()
Expand Down Expand Up @@ -80,6 +88,7 @@ func (s *stringSlice) Set(value string) error {
var (
boilerplateDir string
verbose bool
version bool
excludes stringSlice = []string{
".git",
"vendor",
Expand All @@ -93,8 +102,19 @@ func main() {
flag.StringVar(&boilerplateDir, "boilerplates", "hack/boilerplate/", "Directory containing the boilerplate files for file extensions.")
flag.Var(&excludes, "exclude", fmt.Sprintf("glob expressions (relative to cwd) to exclude, can be given multiple times (%v are excluded by default)", excludes))
flag.BoolVar(&verbose, "verbose", false, "give verbose output regarding why a file does not pass.")
flag.BoolVar(&version, "version", false, "show application version and exit immediately.")
flag.Parse()

if version {
commit := "dev"
if BuildCommit != "" {
commit = BuildCommit[:10]
}

fmt.Printf("boilerplate %s (%s), built with %s on %s\n", BuildTag, commit, runtime.Version(), BuildDate)
return
}

log := logrus.New()
log.SetFormatter(&logrus.TextFormatter{
FullTimestamp: true,
Expand Down

0 comments on commit 23e0bd5

Please sign in to comment.