all repos — legit @ 3889ff9b7bb7d2e429afad79aaf6546c133bd8d5

Unnamed repository; edit this file 'description' to name the repository.

refactor: replace stdlib flag with go-arg for argument parsing
Maxwell Jensen 85795372+maxwelljens@users.noreply.github.com
Tue, 12 May 2026 12:35:45 +0200
commit

3889ff9b7bb7d2e429afad79aaf6546c133bd8d5

parent

607f5d6feaa0fd43c4b1b7a7c227fab33b06c298

3 files changed, 20 insertions(+), 19 deletions(-)

jump to
M go.modgo.mod

@@ -18,6 +18,8 @@ require (

github.com/Microsoft/go-winio v0.6.2 // indirect github.com/ProtonMail/go-crypto v1.1.5 // indirect github.com/acomagu/bufpipe v1.0.4 // indirect + github.com/alexflint/go-arg v1.6.1 // indirect + github.com/alexflint/go-scalar v1.2.0 // indirect github.com/aymerick/douceur v0.2.0 // indirect github.com/cloudflare/circl v1.6.0 // indirect github.com/dlclark/regexp2 v1.11.4 // indirect
M go.sumgo.sum

@@ -12,6 +12,10 @@ github.com/alecthomas/chroma/v2 v2.14.0 h1:R3+wzpnUArGcQz7fCETQBzO5n9IMNi13iIs46aU4V9E=

github.com/alecthomas/chroma/v2 v2.14.0/go.mod h1:QolEbTfmUHIMVpBqxeDnNBj2uoeI4EbYP4i6n68SG4I= github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc= github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= +github.com/alexflint/go-arg v1.6.1 h1:uZogJ6VDBjcuosydKgvYYRhh9sRCusjOvoOLZopBlnA= +github.com/alexflint/go-arg v1.6.1/go.mod h1:nQ0LFYftLJ6njcaee0sU+G0iS2+2XJQfA8I062D0LGc= +github.com/alexflint/go-scalar v1.2.0 h1:WR7JPKkeNpnYIOfHRa7ivM21aWAdHD0gEWHCx+WQBRw= +github.com/alexflint/go-scalar v1.2.0/go.mod h1:LoFvNMqS1CPrMVltza4LvnGKhaSpc3oyLEBUZVhhS2o= github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
M main.gomain.go

@@ -1,14 +1,13 @@

package main import ( - "flag" "fmt" "log" "net/http" - "os" "git.icyphox.sh/legit/config" "git.icyphox.sh/legit/routes" + "github.com/alexflint/go-arg" ) var (

@@ -16,27 +15,23 @@ version = "dev"

buildDate = "unknown" ) -func init() { - flag.Usage = func() { - _, _ = fmt.Fprintf(flag.CommandLine.Output(), "legit %s (built %s)\n\nUsage:\n", version, buildDate) - _, _ = fmt.Fprintf(flag.CommandLine.Output(), " legit [flags]\n\nFlags:\n") - flag.PrintDefaults() - } +type args struct { + Config string `arg:"--config" default:"./config.yaml" help:"path to config file"` +} + +func (args) Description() string { + return fmt.Sprintf("legit %s (built %s)", version, buildDate) +} + +func (args) Version() string { + return fmt.Sprintf("legit %s (built %s)", version, buildDate) } func main() { - var cfg string - var showVersion bool - flag.StringVar(&cfg, "config", "./config.yaml", "path to config file") - flag.BoolVar(&showVersion, "version", false, "print version and exit") - flag.Parse() - - if showVersion { - fmt.Printf("legit %s (built %s)\n", version, buildDate) - os.Exit(0) - } + var a args + arg.MustParse(&a) - c, err := config.Read(cfg) + c, err := config.Read(a.Config) if err != nil { log.Fatal(err) }