alexflint / go-arg

Struct-based argument parsing in Go
https://pkg.go.dev/github.com/alexflint/go-arg
BSD 2-Clause "Simplified" License
2.04k stars 100 forks source link

Incorrect behavior of the built-in help message for the help option #234

Open vanyauhalin opened 11 months ago

vanyauhalin commented 11 months ago

Setup

$ cat go.mod
module main

go 1.21.4

require github.com/alexflint/go-arg v1.4.3

require github.com/alexflint/go-scalar v1.1.0 // indirect
$ cat main.go
package main

import (
    arg "github.com/alexflint/go-arg"
)

type options struct {
    Sub *Sub `arg:"subcommand"`
}

type Sub struct {
    A string `arg:"positional"`
}

func main() {
    var opts options
    arg.MustParse(&opts)
}

Actual

$ go run . sub --help
Usage: main sub [A]

Positional arguments:
  A
  --help, -h             display this help and exit

Expected

$ go run . sub --help
Usage: main sub [A]

Positional arguments:
  A

Global options:
  --help, -h             display this help and exit
alexflint commented 8 months ago

Yeah I think you're right. Will look at changing this. Thanks for reporting!