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

Using only positional arguments panics #280

Open
chipaca opened this issue Oct 10, 2018 · 0 comments · May be fixed by #281
Open

Using only positional arguments panics #280

chipaca opened this issue Oct 10, 2018 · 0 comments · May be fixed by #281

Comments

@chipaca
Copy link
Contributor

chipaca commented Oct 10, 2018

I'm afraid I introduced a bug in fixing #278: now this

package main

import "github.com/jessevdk/go-flags"
import "os"

type options struct {
	Positional struct {
		Bar string `description:"bar"`
	} `positional-args:"yes"`
}

func main() {
	flags.NewParser(&options{}, 0).WriteHelp(os.Stdout)
}

crashes:

panic: strings: negative Repeat count

goroutine 1 [running]:
strings.Repeat(0x4ca350, 0x1, 0xfffffffffffffffe, 0x6, 0x0)
	/snap/go/2644/src/strings/strings.go:538 +0x1c7
github.com/jessevdk/go-flags.(*Parser).WriteHelp(0xc4200b4000, 0x4dd320, 0xc4200a8008)
	/home/john/canonical/snappy/src/github.com/jessevdk/go-flags/help.go:454 +0x511
main.main()
	/tmp/bug5.go:13 +0x6c
exit status 2
chipaca added a commit to chipaca/go-flags that referenced this issue Oct 10, 2018
Without this change, groups that are commands but that don't satisfy
(*Group).showInHelp() would be skipped when working out the alignment,
which would result in negative lengths when trying to process a group
with only positional options.

This fixes jessevdk#280.
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 a pull request may close this issue.

1 participant