Add --version flag and display version on startup

This commit is contained in:
2026-03-29 18:56:03 +02:00
parent 894cd458f5
commit ed9579a40d
3 changed files with 31 additions and 2 deletions

1
.env
View File

@@ -1 +0,0 @@
DSN=root:Maal12345678@tcp(localhost:3306)/nalu

View File

@@ -16,11 +16,33 @@ import (
"gorm.io/gorm"
)
// version returns the current version from git tag and last modification date.
func version() string {
tag := "dev"
if out, err := exec.Command("git", "describe", "--tags", "--abbrev=0").Output(); err == nil {
tag = strings.TrimSpace(string(out))
}
date := ""
if out, err := exec.Command("git", "log", "-1", "--format=%ci").Output(); err == nil {
date = strings.TrimSpace(string(out))
if len(date) >= 10 {
date = date[:10]
}
}
if date != "" {
return fmt.Sprintf("%s (%s)", tag, date)
}
return tag
}
// main is the entry point for the gormcol-gen CLI tool.
// It parses flags, loads configuration from .env, connects to the database,
// and generates GORM models with column descriptors.
func main() {
versionFlag := flag.Bool("version", false, "display version information")
dsn := flag.String("dsn", "", "database DSN (e.g. user:pass@tcp(host:3306)/dbname)")
filter := flag.String("filter", "", "regex to match table names (triggers batch mode)")
all := flag.Bool("all", false, "generate all tables matching filter (shows confirmation)")
@@ -44,7 +66,15 @@ func main() {
flag.Parse()
// Get DSN from flag or environment variable.
// Display version on startup.
fmt.Printf("gormcol %s\n", version())
// Display version if requested.
if *versionFlag {
return
}
// Connect to the database.
dsnValue := *dsn
if dsnValue == "" {
dsnValue = os.Getenv("DSN")

BIN
gormcol

Binary file not shown.