package pflag

import (
	
	
	
)

// following is copied from go 1.23.4 flag.go
type textValue struct{ p encoding.TextUnmarshaler }

func newTextValue( encoding.TextMarshaler,  encoding.TextUnmarshaler) textValue {
	 := reflect.ValueOf()
	if .Kind() != reflect.Ptr {
		panic("variable value type must be a pointer")
	}
	 := reflect.ValueOf()
	if .Kind() == reflect.Ptr {
		 = .Elem()
	}
	if .Type() != .Type().Elem() {
		panic(fmt.Sprintf("default type does not match variable type: %v != %v", .Type(), .Type().Elem()))
	}
	.Elem().Set()
	return textValue{}
}

func ( textValue) ( string) error {
	return .p.UnmarshalText([]byte())
}

func ( textValue) () interface{} {
	return .p
}

func ( textValue) () string {
	if ,  := .p.(encoding.TextMarshaler);  {
		if ,  := .MarshalText();  == nil {
			return string()
		}
	}
	return ""
}

// end of copy
func ( textValue) () string {
	return reflect.TypeOf(.p).String()
}

// GetText set out, which implements encoding.UnmarshalText, to the value of a flag with given name
func ( *FlagSet) ( string,  encoding.TextUnmarshaler) error {
	 := .Lookup()
	if  == nil {
		return fmt.Errorf("flag accessed but not defined: %s", )
	}
	if .Value.Type() != reflect.TypeOf().String() {
		return fmt.Errorf("trying to get %s value of flag of type %s", reflect.TypeOf().String(), .Value.Type())
	}
	return .UnmarshalText([]byte(.Value.String()))
}

// TextVar defines a flag with a specified name, default value, and usage string. The argument p must be a pointer to a variable that will hold the value of the flag, and p must implement encoding.TextUnmarshaler. If the flag is used, the flag value will be passed to p's UnmarshalText method. The type of the default value must be the same as the type of p.
func ( *FlagSet) ( encoding.TextUnmarshaler,  string,  encoding.TextMarshaler,  string) {
	.VarP(newTextValue(, ), , "", )
}

// TextVarP is like TextVar, but accepts a shorthand letter that can be used after a single dash.
func ( *FlagSet) ( encoding.TextUnmarshaler, ,  string,  encoding.TextMarshaler,  string) {
	.VarP(newTextValue(, ), , , )
}

// TextVar defines a flag with a specified name, default value, and usage string. The argument p must be a pointer to a variable that will hold the value of the flag, and p must implement encoding.TextUnmarshaler. If the flag is used, the flag value will be passed to p's UnmarshalText method. The type of the default value must be the same as the type of p.
func ( encoding.TextUnmarshaler,  string,  encoding.TextMarshaler,  string) {
	CommandLine.VarP(newTextValue(, ), , "", )
}

// TextVarP is like TextVar, but accepts a shorthand letter that can be used after a single dash.
func ( encoding.TextUnmarshaler, ,  string,  encoding.TextMarshaler,  string) {
	CommandLine.VarP(newTextValue(, ), , , )
}