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

No error when required arg in subcommand is not provided #226

Closed hueich closed 1 year ago

hueich commented 1 year ago

Hi, I noticed that missing a required arg in a subcommand does not return an error when parsed. E.g.:

type GenerateCmd struct {
  name string `arg:"required"`
}

var mainCmd struct {
  Generate *GenerateCmd `arg:"subcommand:generate"`
}

p, err := NewParser(Config{}, &mainCmd)
// no error here.

if err := p.Parse([]string{"generate"}); err != nil {
  // Should have error, but doesn't.
}

Is this intended? Is it because it's not a positional arg? I'm using v1.4.3.

marco-m commented 1 year ago

Hello, name is lowercase, thus not exported. Try with

type GenerateCmd struct {
  Name string `arg:"required"`
}
hueich commented 1 year ago

Doh, you're right! Thanks for the response.

hueich commented 1 year ago

Not a bug.