mkideal / cli

CLI - A package for building command line app with go
MIT License
731 stars 44 forks source link

panic: interface conversion: interface {} is nil #27

Closed suntong closed 8 years ago

suntong commented 8 years ago

Hey, Please take a look at https://gist.github.com/suntong/cb2bf3d3ada7d7941aac8ef338a815a1#file-dump-go

the previous version was OK (or maybe it didn't work before either, but I can't recall clearly now). Anyway, when running this one, I got the errors like this:

$ go run /tmp/dump.go dump -i /tmp/ii aaa bbbb
panic: interface conversion: interface {} is nil, not *main.rootT

goroutine 1 [running]:
panic(0x7f3020, 0xc820018540)
        /usr/lib/go-1.6/src/runtime/panic.go:464 +0x3e6
main.dumpCLI(0xc8200a0aa0, 0x0, 0x0)
        /tmp/dump.go:72 +0x353
github.com/mkideal/cli.(*Command).RunWith(0xa84ec0, 0xc82000a130, 0x5, 0x5, 0x7f7ebe41e358, 0xc82003c010, 0x0, 0x0, 0x0, 0x0, ...)
        /export/home/u/l/ws/Go/src/github.com/mkideal/cli/command.go:205 +0x58d
github.com/mkideal/cli.(*Command).Run(0xa84ec0, 0xc82000a130, 0x5, 0x5, 0x0, 0x0)
        /export/home/u/l/ws/Go/src/github.com/mkideal/cli/command.go:162 +0x84
main.main()
        /tmp/dump.go:37 +0x134

What's wrong?

mkideal commented 8 years ago

root command should set Global option true:

var root = &cli.Command{
    Name: "dump",
    Desc: "dump assistant program",
    Text: "Swiss-army assistant toolkit",
    Global: true,
    Argv: func() interface{} { return new(rootT) },
    Fn:   dump,

    NumArg: cli.ExactN(1),
}
suntong commented 8 years ago

Thanks a lot!