func parseIter(set *flag.FlagSet, ip iterativeParser, args []string, shellComplete bool) error {
	for {
		err := set.Parse(args)
		if !ip.useShortOptionHandling() || err == nil {
			if shellComplete {
				return nil
			}
			return err
		}
		errStr := err.Error()
		trimmed := strings.TrimPrefix(errStr, "flag provided but not defined: -")
		if errStr == trimmed {
			return err
		}
		argsWereSplit := false
		for i, arg := range args {
			if name := strings.TrimLeft(arg, "-"); name != trimmed {
				continue
			}
			shortOpts := splitShortOptions(set, arg)
			if len(shortOpts) == 1 {
				return err
			}
			args = append(args[:i], append(shortOpts, args[i+1:]...)...)
			argsWereSplit = true
			break
		}
		if !argsWereSplit {
			return err
		}
		newSet, err := ip.newFlagSet()
		if err != nil {
			return err
		}
		*set = *newSet
	}
}
To enable short-option handling (e.g., "-it" vs "-i -t") we have to
iteratively catch parsing errors. This way we achieve LR parsing without
transforming any arguments. Otherwise, there is no way we can discriminate
combined short options from common arguments that should be left untouched.
Pass `shellComplete` to continue parsing options on failure during shell
completion when, the user-supplied options may be incomplete.
package cli
import (
	"flag"
	"strings"
)
type iterativeParser interface {
	newFlagSet() (*flag.FlagSet, error)
	useShortOptionHandling() bool
}