Skip to content

Inheritable options causes panic #17

@myOmikron

Description

@myOmikron

Hi there,

func main() {	
        parser := argparse.NewParser("q-scheduler", "", nil)

	startParser := parser.AddCommand("start", "Starts the scheduler", &argparse.ParserConfig{
		DisableHelp: true,
	})

	initParser := parser.AddCommand("init", "", &argparse.ParserConfig{
		DisableHelp: true,
	})

	configPath := parser.String("", "config-path", &argparse.Option{
		Default:     "/etc/q-scheduler/config.toml",
		Help:        "Path to the configuration file of q-scheduler.",
		Inheritable: true,
	})

	if err := parser.Parse(nil); err != nil {
		fmt.Println(err.Error())
		return
	}
}

This panics:

omikron@xps13 ~/g/q-scheduler (main) [1]> go run cmd/q-scheduler/main.go start --config-path abc
panic: runtime error: slice bounds out of range [1:0]

goroutine 1 [running]:
github.com/hellflame/argparse.min({0xe57678?, 0x84210842?, 0xc0001738c0?})
        /opt/go/pkg/mod/github.com/hellflame/argparse@v1.8.0/levenshtein.go:63 +0x7c
github.com/hellflame/argparse.decideMatch({0x7ffcaffd478c, 0xd}, {0x0, 0x0, 0xc0002da460?})
        /opt/go/pkg/mod/github.com/hellflame/argparse@v1.8.0/levenshtein.go:8 +0x87
github.com/hellflame/argparse.(*Parser).Parse(0xc0002da380, {0xc000132020?, 0x7ffcaffd4786?, 0x5?})
        /opt/go/pkg/mod/github.com/hellflame/argparse@v1.8.0/parse.go:502 +0x88d
github.com/hellflame/argparse.(*Parser).Parse(0xc0002da1c0, {0x0?, 0x0?, 0xa4849d?})
        /opt/go/pkg/mod/github.com/hellflame/argparse@v1.8.0/parse.go:432 +0x19b
main.main()
        /home/omikron/git/q-scheduler/cmd/q-scheduler/main.go:28 +0x145
exit status 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions