package pflagfork

import (
	
	
	

	
	
	
)

// mode defines how flags are represented.
type mode int

const (
	Default         mode = iota // default behaviour
	ShorthandOnly               // only the shorthand should be used
	NameAsShorthand             // non-posix mode where the name is also added as shorthand (single prefix)
)

type Flag struct {
	*pflag.Flag
	ArgPrefix  string   // e.g., "--verbose=" when completing --verbose=foo
	FlagPrefix rune     // flag prefix character from parent FlagSet (e.g. '-', '&')
	Args       []string // already-consumed flag arguments
}

func ( Flag) () int {
	if  := reflect.ValueOf(.Flag).Elem().FieldByName("Nargs"); .IsValid() && .Kind() == reflect.Int {
		return int(.Int())
	}
	return 0
}

// ArgumentStyle bit values mirror github.com/carapace-sh/carapace-pflag
// ArgumentStyle constants (accessed via reflection since pflagfork
// cannot import carapace-pflag).
const (
	argStyleNext      uint = 1 << iota // AcceptNext: -f arg
	argStyleDelimited                  // AcceptDelimited: -f=arg
	argStyleAttached                   // AcceptAttached: -farg (POSIX shorthand only)
)

func ( Flag) () bool {
	return .ArgumentStyle() == 0 || .ArgumentStyle()&argStyleNext != 0
}

func ( Flag) () bool {
	return .ArgumentStyle() == 0 || .ArgumentStyle()&argStyleDelimited != 0
}

func ( Flag) () bool {
	return .ArgumentStyle() == 0 || .ArgumentStyle()&argStyleAttached != 0
}

func ( Flag) () rune {
	if  := reflect.ValueOf(.Flag).Elem().FieldByName("OptargDelimiter"); .IsValid() && .Kind() == reflect.Int32 {
		return (rune(.Int()))
	}
	return '='
}

// DelimiterDisabled reports whether OptargDelimiter is set to a value
// that disables delimiter-based argument parsing (e.g. -1), meaning
// attached values are parsed directly: -rvalue instead of -r=value.
func ( Flag) () bool {
	return .OptargDelimiter() < 0x20
}

func ( Flag) () uint {
	if  := reflect.ValueOf(.Flag).Elem().FieldByName("ArgumentStyle"); .IsValid() && .Kind() == reflect.Uint {
		return uint(.Uint())
	}
	return 0 // 0 means accept all variants (backward compatible)
}

func ( Flag) () mode {
	if  := reflect.ValueOf(.Flag).Elem().FieldByName("Mode"); .IsValid() && .Kind() == reflect.Int {
		return mode(.Int())
	}
	return Default
}

func ( Flag) () bool {
	if strings.Contains(.Value.Type(), "Slice") ||
		strings.Contains(.Value.Type(), "Array") ||
		.Value.Type() == "count" {
		return true
	}
	return false
}

func ( Flag) () bool {
	switch .Value.Type() {
	case "bool", "boolSlice", "count":
		return false
	default:
		return true
	}
}

func ( Flag) () bool {
	return .NoOptDefVal != ""
}

func ( Flag) () string {
	switch {
	case !.TakesValue():
		return style.Carapace.FlagNoArg
	case .IsOptarg():
		return style.Carapace.FlagOptArg
	case .Nargs() != 0:
		return style.Carapace.FlagMultiArg
	default:
		return style.Carapace.FlagArg
	}
}

func ( Flag) () bool {
	if  := .Annotations[cobra.BashCompOneRequiredFlag]; len() == 1 && [0] == "true" {
		return true
	}
	return false
}

func ( Flag) ( rune) string {
	 := string()
	var  string
	switch .GetMode() {
	case ShorthandOnly:
		 = fmt.Sprintf("%v%v", , .Shorthand)
	case NameAsShorthand:
		 = fmt.Sprintf("%v%v, %v%v", , .Shorthand, , .Name)
	default:
		switch .Shorthand {
		case "":
			 = fmt.Sprintf("%v%v%v", , , .Name)
		default:
			 = fmt.Sprintf("%v%v, %v%v%v", , .Shorthand, , , .Name)
		}
	}

	if .Hidden {
		 += "&"
	}

	if .Required() {
		 += "!"
	}

	if .IsRepeatable() {
		 += "*"
	}

	switch {
	case .IsOptarg():
		switch .Value.Type() {
		case "bool", "boolSlice", "count":
		default:
			 += "?"
		}
	case .TakesValue():
		 += "="
	}

	return 
}

func ( Flag) ( string) bool {
	switch {
	case .Flag == nil:
		return false
	case !.TakesValue():
		return false
	case .IsOptarg():
		return false
	case len(.Args) == 0:
		return true
	case .Nargs() > 1 && len(.Args) < .Nargs():
		return true
	case .Nargs() < 0 && !strings.HasPrefix(, string(.FlagPrefix)):
		return true
	default:
		return false
	}
}