jessevdk / go-flags

go command line option parser
http://godoc.org/github.com/jessevdk/go-flags
BSD 3-Clause "New" or "Revised" License
2.56k stars 305 forks source link

Multiple short options are not detected with `IgnoreUnknown` flag. #399

Open ghost opened 1 year ago

ghost commented 1 year ago

Stacked short options are not recognized after first unknown option (even with flag IgnoreUnknown).

Following code sample:

package main

import (
    "fmt"

    "github.com/jessevdk/go-flags"
)

var first struct {
    Query bool `short:"Q" long:"query"`
}

var second struct {
    Quick bool `short:"q" long:"quick"`
}

func main() {
    flags.NewParser(&first, flags.IgnoreUnknown).Parse()
    fmt.Println(first)

    flags.NewParser(&second, flags.IgnoreUnknown).Parse()
    fmt.Println(second)
}

Produces results:

 > go run . -Qq
{true}
{false}
 > go run . -qQ  
{false}
{true}
 > go run . -Q -q
{true}
{true}

I expect true&true in each run, but results are different.