alexflint / go-arg

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

similar to subcommand, I would like to have subarg #126

Open kernel164 opened 3 years ago

kernel164 commented 3 years ago

Here is the idea...

type MainOpts struct {
    Port    int `arg:"--port"`
    Inner InnerOpts `arg:"subarg:inner"`
}
type InnerOpts struct {
    Enabled bool `arg:"enabled"`
}

should become

--port
--inner-enabled

Don't know whether it is already supported but this nicely fits in for nested structs. It's similar to custom parsing for values but for arg names.

alexflint commented 3 years ago

Yes this is do-able but I fear that it would add more complexity than it's worth, and would make it more difficult to understand code that uses this library. Are there really cases when you want to repeat a significant number of inner options at different places within the same program?

kernel164 commented 3 years ago

Our requirement is similar to this => https://doc.traefik.io/traefik/v2.3/reference/static-configuration/cli/

possibly there could be 3 or 4 levels of inner struct.

kernel164 commented 3 years ago

we used kingpin => https://github.com/alecthomas/kingpin but we would like to move to go-arg.

Idea is to have go-arg,config(yaml,json.. etc) parse into same struct.

alexflint commented 3 years ago

Got it. Seems reasonable, and fun to implement :). I'm about to go into a meditation retreat but will try to find time for this afterwards.

alexflint commented 3 years ago

Would you be interested in providing some funding to me in order to implement this feature?

kernel164 commented 3 years ago

I just do opensource projects like you. I started using go-arg for my new codes. thought of having this feature in my new projects. I can contribute as code though.

alexflint commented 3 years ago

OK @kernel164, I'd be happy to review a pull request