diff --git a/.goreleaser.yaml b/.goreleaser.yaml index eecc0df..614cd09 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -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 diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..bfa1c23 --- /dev/null +++ b/.tool-versions @@ -0,0 +1,2 @@ +golang 1.22.2 +goreleaser 1.25.1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 708a061..beb799f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/justfile b/justfile index af52fa3..2f62a4a 100644 --- a/justfile +++ b/justfile @@ -1,5 +1,11 @@ # 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}}:" @@ -7,5 +13,11 @@ release 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 + +changeset: + npx changeset + +hash: + git rev-parse --short HEAD diff --git a/main.go b/main.go index 0f87a0c..3b54e08 100644 --- a/main.go +++ b/main.go @@ -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 == "" { @@ -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()) diff --git a/radicle_init.log b/radicle_init.log new file mode 100644 index 0000000..bb7998b --- /dev/null +++ b/radicle_init.log @@ -0,0 +1,21 @@ +inovakov unique % rad init 35ms + +Initializing radicle 👾 repository in /Users/inovakov/source/unique.. + +✓ Name unique +✓ Description Reads a file and outputs all unique lines. +✓ Default branch main +✓ Visibility public +✓ Repository unique created. + +Your Repository ID (RID) is rad:z4MMHetnbTkfuZtc5jMapMavrmQth. +You can show it any time by running `rad .` from this directory. + +✓ Repository successfully synced to 1 node(s). + +Your repository has been synced to the network and is now discoverable by peers. +View it in your browser at: + + https://app.radicle.xyz/nodes/seed.radicle.garden/rad:z4MMHetnbTkfuZtc5jMapMavrmQth + +To push changes, run `git push rad main`.