mow.cli icon indicating copy to clipboard operation
mow.cli copied to clipboard

Expose CLI model

Open jawher opened this issue 5 years ago • 6 comments
trafficstars

app.Model()

Fixes #104

jawher avatar Jul 03 '20 14:07 jawher

Coverage Status

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

coveralls avatar Jul 03 '20 14:07 coveralls

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/[email protected]/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/[email protected]/commands.go:167 +0x9fc
github.com/jawher/mow%2ecli.(*Cli).Model(...)
	/path/to/gocode/pkg/mod/github.com/jawher/[email protected]/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?

skyzyx avatar Jul 17 '20 22:07 skyzyx

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

jawher avatar Jul 18 '20 08:07 jawher

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

skyzyx avatar Nov 16 '20 02:11 skyzyx

Ping

mmeloni avatar Oct 09 '23 14:10 mmeloni

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

skyzyx avatar Oct 09 '23 17:10 skyzyx