Skip to content

Commit

Permalink
Add a version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaub committed Nov 10, 2024
1 parent 9e6fb6b commit 6236211
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 6236211

Please sign in to comment.