go-flags icon indicating copy to clipboard operation
go-flags copied to clipboard

Fix multiple short options with `IgnoreUnknown` option

Open d1nch8g opened this issue 1 year ago • 0 comments

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}

d1nch8g avatar Nov 19 '23 22:11 d1nch8g