Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add version #8

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@ changelog:

brews:
- name: unique
alternative_names:
- unique@{{ .Version }}
- unique@{{ .Major }}.{{ .Minor }}
- unique@{{ .Major }}
description: "Outputs the unique lines of its input"
homepage: "https://github.com/ro-tex/unique"
license: "MIT"
folder: Formula
directory: Formula
url_template: "https://github.com/ro-tex/unique/releases/download/{{ .Tag }}/{{ .ArtifactName }}"
commit_author:
name: goreleaserbot
Expand Down
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
golang 1.22.2
goreleaser 1.25.1
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add `--version` command that outputs version and commit hash.

### Changed

- Switched to using v2 of xxhash library.
Expand Down
10 changes: 8 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# https://github.com/casey/just

build:
goreleaser build --clean --snapshot

buildWithVersion version commitHash:
go build -ldflags "-X main.version={{version}} -X main.commit={{commitHash}}" .

release version:
@[[ "{{version}}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] # ensure semantic versioning
@echo "Creating a release for version {{version}}:"
git tag -a {{version}} -m "{{version}}"
git push origin {{version}}
goreleaser release --clean

sign-last-commit:
git commit --amend --no-edit -S
sign-last-commit:
git commit --amend --no-edit -S
14 changes: 14 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ const (
defaultLineLengthLimit = 100 * 1024 * 1024 // 100 MiB
)

var (
// These variables are set at build time by GoReleaser. See https://goreleaser.com/cookbooks/using-main.version/
version = "dev"
commit = "none"
)

// readFile opens the given file for reading and returns a reader and a closing function.
func readFile(path string, lineLimit int) (r *bufio.Reader, closeFn func() error, err error) {
if path == "" {
Expand Down Expand Up @@ -104,11 +110,19 @@ func main() {
var filePath string
var trim bool
var lineLengthLimit int
var versionFlag bool
flag.StringVar(&filePath, "f", "", "path to the file to process")
flag.BoolVar(&trim, "t", false, "trim whitespace from each line (default false)")
flag.IntVar(&lineLengthLimit, "ll", defaultLineLengthLimit, "limit the length of each line being processed, ignoring any data beyond that length (values under 16 are ignored)")
flag.BoolVar(&versionFlag, "version", false, "print the version")
flag.Parse()

// Print the version and exit.
if versionFlag {
fmt.Println(version, commit)
return
}

reader, closeFn, err := readFile(filePath, lineLengthLimit)
if err != nil {
log.Fatalf("Failed to read from file '%s'. Error: %s\n", filePath, err.Error())
Expand Down