diff --git a/.env b/.env deleted file mode 100644 index 3deb853..0000000 --- a/.env +++ /dev/null @@ -1 +0,0 @@ -DSN=root:Maal12345678@tcp(localhost:3306)/nalu diff --git a/cmd/gormcol/main.go b/cmd/gormcol/main.go index 5176187..759631b 100644 --- a/cmd/gormcol/main.go +++ b/cmd/gormcol/main.go @@ -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") diff --git a/gormcol b/gormcol deleted file mode 100755 index 6725cad..0000000 Binary files a/gormcol and /dev/null differ