jawher / mow.cli

A versatile library for building CLI applications in Go
MIT License
872 stars 55 forks source link

Expose CLI model #106

Open jawher opened 4 years ago

jawher commented 4 years ago

app.Model()

Fixes #104

coveralls commented 4 years ago

Coverage Status

Coverage decreased (-2.9%) to 92.68% when pulling 3da148f7177beeceae5c5bd927c86594c944fb73 on issue-104-app-model into fbc50e90e1fb96a3ddde67f9ca6289b8054f2f7e on master.

skyzyx commented 4 years ago

Getting a panic.

Pulled this branch:

GO111MODULE=on go get github.com/jawher/mow.cli@issue-104-app-model

Here's a pared-down file that shows the issue:

package main

import (
    "os"

    "github.com/davecgh/go-spew/spew"
    cli "github.com/jawher/mow.cli"
)

func main() {
    app := cli.App("myapp", "Description.")
    app.Version("version", "1")

    app.Command("do", "Do the thing.", func(config *cli.Cmd) {})

    spew.Dump(app.Model())

    err = app.Run(os.Args)
    if err != nil {
        exitErrorf(err)
    }
}

And the panic.

panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/jawher/mow%2ecli.(*Cmd).Model(0xc00014e200, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
    /path/to/gocode/pkg/mod/github.com/jawher/mow.cli@v1.1.1-0.20200703143524-5e525d076aa4/commands.go:157 +0xaec
github.com/jawher/mow%2ecli.(*Cmd).Model(0xc00014e100, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
    /path/to/gocode/pkg/mod/github.com/jawher/mow.cli@v1.1.1-0.20200703143524-5e525d076aa4/commands.go:167 +0x9fc
github.com/jawher/mow%2ecli.(*Cli).Model(...)
    /path/to/gocode/pkg/mod/github.com/jawher/mow.cli@v1.1.1-0.20200703143524-5e525d076aa4/cli.go:71
main.main()
    /path/to/gocode/src/github.com/skyzyx/project/src/main.go:16 +0x197

I don't see anything obvious in the code other than commands.go:157 references make() with a specific len as the second parameter. Maybe it's miscalculating?

jawher commented 4 years ago

@skyzyx Nice catch ! I just pushed a commit to fix a bug in a slice allocation len 🤦‍♂️

skyzyx commented 3 years ago

Had a chance to come back to this, and I'm quite happy with the results. THANK YOU!

mmeloni commented 11 months ago

Ping

skyzyx commented 11 months ago

This is available on the master branch, but has not been cut into a release.