From cfa73f12e21591855f0f82a880b3be84151bba0d Mon Sep 17 00:00:00 2001 From: Naoto Takai Date: Mon, 19 Jan 2026 21:15:35 +0900 Subject: [PATCH] feat(cli): add version flag --- .goreleaser.yaml | 2 ++ cmd/git-ai-commit/main.go | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 5c345d3..3159035 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -4,6 +4,8 @@ builds: - id: git-ai-commit main: ./cmd/git-ai-commit binary: git-ai-commit + ldflags: + - -s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} env: - CGO_ENABLED=0 goos: diff --git a/cmd/git-ai-commit/main.go b/cmd/git-ai-commit/main.go index 2510e7b..f348b3c 100644 --- a/cmd/git-ai-commit/main.go +++ b/cmd/git-ai-commit/main.go @@ -9,6 +9,11 @@ import ( "git-ai-commit/internal/app" ) +var ( + version = "dev" + commit = "none" +) + type options struct { context string contextFile string @@ -29,6 +34,10 @@ func main() { printUsage(os.Stdout) return } + if errors.Is(err, errVersion) { + printVersion() + return + } fmt.Fprintln(os.Stderr, err) printUsage(os.Stderr) os.Exit(2) @@ -51,6 +60,7 @@ func main() { } var errHelp = errors.New("help requested") +var errVersion = errors.New("version requested") func parseArgs(args []string) (options, error) { var opts options @@ -64,6 +74,8 @@ func parseArgs(args []string) (options, error) { switch name { case "help": return opts, errHelp + case "version": + return opts, errVersion case "context", "context-file", "prompt", "prompt-file", "engine", "include": if !hasValue { if i+1 >= len(args) { @@ -180,4 +192,9 @@ func printUsage(out *os.File) { fmt.Fprintln(out, " --debug-prompt Print the prompt before executing the engine") fmt.Fprintln(out, " --debug-command Print the engine command before execution") fmt.Fprintln(out, " -h, --help Show help") + fmt.Fprintln(out, " --version Show version information") +} + +func printVersion() { + fmt.Printf("git-ai-commit version %s (%s)\n", version, commit) }