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
	Prefix string
	Args   []string
}

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

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

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

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) () string {
	var  string
	switch .Mode() {
	case ShorthandOnly:
		 = fmt.Sprintf("-%v", .Shorthand)
	case NameAsShorthand:
		 = fmt.Sprintf("-%v, -%v", .Shorthand, .Name)
	default:
		switch .Shorthand {
		case "":
			 = fmt.Sprintf("--%v", .Name)
		default:
			 = fmt.Sprintf("-%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(, "-"):
		return true
	default:
		return false
	}
}