go-flags
go-flags copied to clipboard
Fix multiple short options with `IgnoreUnknown` option
Related to Issue:
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)
}
Before fix:
> go run . -Qq
{true}
{false}
> go run . -qQ
{false}
{true}
> go run . -Q -q
{true}
{true}
After fix:
> go run . -Qq
{true}
{true}
> go run . -qQ
{true}
{true}
> go run . -Q -q
{true}
{true}