Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remainder not supported with Verbs #12

Open
jagipson opened this issue Feb 20, 2015 · 4 comments
Open

Remainder not supported with Verbs #12

jagipson opened this issue Feb 20, 2015 · 4 comments

Comments

@jagipson
Copy link

I'm just getting started in Go and should probably NOT submit any code yet, however when using your excellent options library that I read about here (http://dave.cheney.net/2013/11/07/subcommand-handling-in-go). I ran into a problem. The solution might just be to amend the documentation, or perhaps there's an actual fix. But when I used Remainder in the top level struct with verbs, I got a nasty reflect error:

panic: reflect: NumField of non-struct type

goroutine 1 [running]:
reflect.(*rtype).NumField(0x5e5560, 0xc20802e530)
/images/opt/go/src/reflect/type.go:657 +0x7a
github.com/voxelbrain/goptions.newFlagset(0x0, 0x0, 0x5e5560, 0xc20802e530, 0xd7, 0xc2080117a0, 0x7ffb282ca7e8)
/home/jagipson/go/src/github.com/voxelbrain/goptions/flagset.go:66 +0x23c
github.com/voxelbrain/goptions.newFlagset(0x695710, 0x4, 0x664e00, 0xc20802e500, 0xd9, 0x0, 0x7ffb282bd000)
/home/jagipson/go/src/github.com/voxelbrain/goptions/flagset.go:102 +0x889
github.com/voxelbrain/goptions.NewFlagSet(0x695710, 0x4, 0x5d5be0, 0xc20802e500, 0x0)
/home/jagipson/go/src/github.com/voxelbrain/goptions/flagset.go:46 +0x1a6
main.main()
/home/jagipson/go/src/github.com/jagipson/goreps/cmd/reps/reps.go:55 +0x84
exit status 2

That happens for this:

options := struct {
    DataStorePath string        `goptions:"-d, --datastore, description='Specify DataStore path. (default: ~/.gorepsdata)'"`
    Verbosity     bool          `goptions:"-v, --verbose", description='firehose verbosity'"`
    Help          goptions.Help `goptions:"-h, --help, description='Show this help'"`

    goptions.Verbs
    List struct {
        Colorize bool `goptions:"-c, --color, description='Colorize the output (not implemented yet)'"`
        Long     bool `goptions:"-l, --long, description='extra data'"`
        Help     bool `goptions:"-h, --help, description='Print List Help'"`

        goptions.Verbs
        Models struct{} `goptions:"models"`
        Items  struct{} `goptions:"items"`
    } `goptions:"list"`

    New struct {
        Foo bool `goptions:"-f"`
    } `goptions:"new"`

    Remainder goptions.Remainder
}{}

And goes away when I comment out the Remainder line

@jagipson
Copy link
Author

A tangential issue related to documentation:

I discovered that deeply nested verbs was possible, and specifically needed that feature. The docs might mention that verbs can be nested deeper than level 1, that is, that a verb struct may, itself, contain sub-verbs in addition to the already documented capability of containing flags.

@surma
Copy link
Collaborator

surma commented Feb 20, 2015

Thanks for opening issue! Your comment regarding the documentation is definitely valid. It just never occured to me to make something like that explicit as I thought of goptions parser as recursive in general ;)

The Remainder issue is a bug, I’m just contemplating whether to actually fix it as I’m drafting goptions v3 right now.

If you, however, feel like fixing this yourself, please go ahead and make a pull-request. I will gladly review your code, esp. if you are just getting started :)

@jagipson
Copy link
Author

I'd never be able to fix anything that uses reflect

@jagipson jagipson reopened this Feb 20, 2015
@donatj
Copy link

donatj commented Aug 8, 2018

Came here intending to report the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants