Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 17 additions & 0 deletions cmd/git-ai-commit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import (
"git-ai-commit/internal/app"
)

var (
version = "dev"
commit = "none"
)

type options struct {
context string
contextFile string
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
}