From 2470f4f24de80b3f236b81b246d8e8ffc2a69507 Mon Sep 17 00:00:00 2001 From: Daniele Sluijters Date: Tue, 12 Mar 2024 12:22:33 +0100 Subject: [PATCH] Add version information and flag --- main.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/main.go b/main.go index 1b69ed3..84d1c75 100644 --- a/main.go +++ b/main.go @@ -12,10 +12,30 @@ import ( "github.com/expr-lang/expr" ) +var ( + version = "unknown" + commit = "unknown" + date = "unknown" +) + func main() { scripts := flag.String("scripts-dir", "", "path to load .expr scripts from") + showVersion := flag.Bool("version", false, "print version and exit") + flag.Usage = func() { + fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n\n", os.Args[0]) + fmt.Fprintf(flag.CommandLine.Output(), "Parameters:\n\n") + flag.PrintDefaults() + fmt.Fprintf(flag.CommandLine.Output(), "\n") + fmt.Fprintf(flag.CommandLine.Output(), "Version: %s, Commit: %s, Date: %s\n", version, commit, date) + fmt.Fprintf(flag.CommandLine.Output(), "\n") + } flag.Parse() + if *showVersion { + fmt.Fprintf(os.Stdout, "Version: %s, Commit: %s, Date: %s\n", version, commit, date) + os.Exit(0) + } + if *scripts == "" { fmt.Println("please provide a directory to load scripts from") os.Exit(1)