diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..160c62e --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +## Env +.envrc + +## Go +/dist +/vendor diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..60c05d3 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,48 @@ +project_name: zap-pretty +before: + hooks: + - go mod download + - go generate ./... +builds: +- env: + - CGO_ENABLED=0 +archive: + replacements: + darwin: Darwin + linux: Linux + windows: Windows + amd64: x86_64 + files: + - LICENSE.md + - README.md + - CHANGELOG.md +checksum: + name_template: 'checksums.txt' +sign: + cmd: keybase + args: + - sign + - --infile + - $artifact + - --binary + - --outfile + - $signature + - --detached + signature: ${artifact}.sig + artifacts: checksum +snapshot: + name_template: "{{ .Tag }}-dirty" +brew: + github: + owner: maoueh + name: homebrew-tap + homepage: "https://github.com/maoueh/zap-pretty" + description: "A tiny binary to pretty-print Zap production JSON lines" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' + - '^support:' + - '^chore:' diff --git a/main.go b/main.go index 38e8df0..0adf40b 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "bytes" "encoding/json" "errors" + "flag" "fmt" "io" "io/ioutil" @@ -21,6 +22,13 @@ import ( var debug = log.New(ioutil.Discard, "", 0) var severityToColor map[string]Color +// Provided via ldflags by goreleaser automatically +var ( + version = "dev" + commit = "none" + date = "unknown" +) + var errNonZapLine = errors.New("non-zap line") func init() { @@ -43,7 +51,16 @@ type processor struct { output io.Writer } +var versionFlag = flag.Bool("version", false, "Prints version information and exit") + func main() { + flag.Parse() + + if *versionFlag { + printVersion() + os.Exit(0) + } + processor := &processor{ scanner: bufio.NewScanner(os.Stdin), output: os.Stdout, @@ -52,6 +69,10 @@ func main() { processor.process() } +func printVersion() { + fmt.Printf("zap-pretty %s (commit: %s, date: %v)\n", version, commit, date) +} + func (p *processor) process() { first := true for p.scanner.Scan() {