From 2a6498dae1bddac0bed02c9e66980906531b2567 Mon Sep 17 00:00:00 2001 From: m3ta-chiron Date: Sat, 22 Aug 2026 21:41:05 +0200 Subject: [PATCH] feat: scaffold Go module with version command, Makefile and goreleaser config --- .goreleaser.yaml | 53 +++++++++++++++++++++++++++++++++++++ Makefile | 26 ++++++++++++++++++ go.mod | 10 +++++++ go.sum | 10 +++++++ internal/cli/root.go | 44 ++++++++++++++++++++++++++++++ internal/version/version.go | 7 +++++ main.go | 13 +++++++++ 7 files changed, 163 insertions(+) create mode 100644 .goreleaser.yaml create mode 100644 Makefile create mode 100644 go.mod create mode 100644 go.sum create mode 100644 internal/cli/root.go create mode 100644 internal/version/version.go create mode 100644 main.go diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..e8d776f --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,53 @@ +version: 2 + +project_name: agent-lib + +before: + hooks: + - go mod tidy + +builds: + - id: agent-lib + env: + - CGO_ENABLED=0 + goos: + - windows + - linux + - darwin + goarch: + - amd64 + - arm64 + ignore: + - goos: windows + goarch: arm64 + ldflags: + - -s -w -X github.com/m3tam3re/agent-lib/internal/version.Version={{.Version}} + binary: agent-lib + +checksum: + name_template: "checksums.txt" + +archives: + - id: agent-lib + formats: [tar.gz] + format_overrides: + - goos: windows + formats: [zip] + +release: + github: + owner: m3tam3re + name: agent-lib + draft: false + prerelease: auto + mode: append + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" + - "^chore:" + - Merge pull request + - Merge branch diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7339445 --- /dev/null +++ b/Makefile @@ -0,0 +1,26 @@ +BINARY := agent-lib +VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev) +LDFLAGS := -s -w -X github.com/m3tam3re/agent-lib/internal/version.Version=$(VERSION) + +.PHONY: build test vet lint fmt fmt-check clean + +build: + go build -ldflags '$(LDFLAGS)' -o $(BINARY) . + +test: + go test ./... + +vet: + go vet ./... + +fmt: + gofmt -w . + +fmt-check: + @out=$$(gofmt -l .); if [ -n "$$out" ]; then \ + echo "gofmt required on:"; echo "$$out"; exit 1; fi + +lint: vet fmt-check + +clean: + rm -rf $(BINARY) dist/ diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..f5046bd --- /dev/null +++ b/go.mod @@ -0,0 +1,10 @@ +module github.com/m3tam3re/agent-lib + +go 1.26.5 + +require github.com/spf13/cobra v1.10.2 + +require ( + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/spf13/pflag v1.0.9 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..a6ee3e0 --- /dev/null +++ b/go.sum @@ -0,0 +1,10 @@ +github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU= +github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4= +github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY= +github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/internal/cli/root.go b/internal/cli/root.go new file mode 100644 index 0000000..1c433a7 --- /dev/null +++ b/internal/cli/root.go @@ -0,0 +1,44 @@ +// Package cli wires the agent-lib command tree: vendor (curator side), +// sync/status (client side) and version. +package cli + +import ( + "fmt" + "io" + "runtime" + + "github.com/spf13/cobra" + + "github.com/m3tam3re/agent-lib/internal/version" +) + +func NewRootCmd() *cobra.Command { + root := &cobra.Command{ + Use: "agent-lib", + Short: "Curated agent content: vendor external sources, sync to OpenCode", + SilenceUsage: true, + SilenceErrors: true, + } + root.AddCommand(newVersionCmd()) + return root +} + +func newVersionCmd() *cobra.Command { + return &cobra.Command{ + Use: "version", + Short: "Print the agent-lib version", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + return printVersion(cmd.OutOrStdout()) + }, + } +} + +func printVersion(w io.Writer) error { + _, err := fmt.Fprintf(w, "agent-lib %s (%s/%s)\n", version.Version, runtime.GOOS, runtime.GOARCH) + return err +} + +func Execute() error { + return NewRootCmd().Execute() +} diff --git a/internal/version/version.go b/internal/version/version.go new file mode 100644 index 0000000..e429f24 --- /dev/null +++ b/internal/version/version.go @@ -0,0 +1,7 @@ +// Package version carries the build-time version of the agent-lib binary. +package version + +// Version is injected at build time via +// -ldflags "-X internal/version.Version=". It defaults to "dev" +// for plain `go build` runs. +var Version = "dev" diff --git a/main.go b/main.go new file mode 100644 index 0000000..97a5d56 --- /dev/null +++ b/main.go @@ -0,0 +1,13 @@ +package main + +import ( + "os" + + "github.com/m3tam3re/agent-lib/internal/cli" +) + +func main() { + if err := cli.Execute(); err != nil { + os.Exit(1) + } +}