Skip to content

Expose CLI model#106

Draft
jawher wants to merge 3 commits into
masterfrom
issue-104-app-model
Draft

Expose CLI model#106
jawher wants to merge 3 commits into
masterfrom
issue-104-app-model

Conversation

@jawher

@jawher jawher commented Jul 3, 2020

Copy link
Copy Markdown
Owner

app.Model()

Fixes #104

@coveralls

coveralls commented Jul 3, 2020

Copy link
Copy Markdown

Coverage Status

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

@skyzyx

skyzyx commented Jul 17, 2020

Copy link
Copy Markdown

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

jawher commented Jul 18, 2020

Copy link
Copy Markdown
Owner Author

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

@jawher jawher force-pushed the issue-104-app-model branch from 3da148f to 519fe99 Compare August 13, 2020 10:32
@skyzyx

skyzyx commented Nov 16, 2020

Copy link
Copy Markdown

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

@mmeloni

mmeloni commented Oct 9, 2023

Copy link
Copy Markdown

Ping

@skyzyx

skyzyx commented Oct 9, 2023

Copy link
Copy Markdown

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

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

Successfully merging this pull request may close these issues.

Expose a model of the command structure

4 participants