From 62362115fc8fe384b48409a99367fddfdee0befb Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 10 Nov 2024 14:45:25 -0700 Subject: [PATCH] Add a version flag --- main.go | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index ec48024..91eee6f 100644 --- a/main.go +++ b/main.go @@ -18,20 +18,32 @@ import ( "github.com/rs/cors" ) +var ( + // set by goreleaser + version = "development" +) + func main() { - ctx := kong.Parse(&Serve{}, kong.UsageOnError()) + ctx := kong.Parse( + &Serve{}, + kong.UsageOnError(), + kong.Vars{ + "version": version, + }, + ) err := ctx.Run() ctx.FatalIfErrorf(err) } type Serve struct { - Port int `help:"Listen on this port." default:"4000"` - Dir string `help:"Serve files from this directory." arg:"" type:"existingdir"` - Prefix string `help:"Prefix all URL paths with this value." default:"/"` - Cors bool `help:"Include CORS support (on by default)." default:"true" negatable:""` - Dot bool `help:"Serve dot files (files prefixed with a '.')." default:"false"` - ExplicitIndex bool `help:"Only serve index.html files if URL path includes it." default:"false"` - Spa bool `help:"Serve the index.html file for all unknown paths." default:"false"` + Port int `help:"Listen on this port." default:"4000"` + Dir string `help:"Serve files from this directory." arg:"" type:"existingdir"` + Prefix string `help:"Prefix all URL paths with this value." default:"/"` + Cors bool `help:"Include CORS support (on by default)." default:"true" negatable:""` + Dot bool `help:"Serve dot files (files prefixed with a '.')." default:"false"` + ExplicitIndex bool `help:"Only serve index.html files if URL path includes it." default:"false"` + Spa bool `help:"Serve the index.html file for all unknown paths." default:"false"` + Version kong.VersionFlag `help:"Print the version and exit."` } func normalizePrefix(base string, prefix string) (string, error) {