AlecAivazis / survey

A golang library for building interactive and accessible prompts with full support for windows and posix terminals.
MIT License
4.08k stars 351 forks source link

Take UnmarshalText into account when writing answer #332

Closed florisvdg closed 3 years ago

florisvdg commented 3 years ago

It would be nice for core.WriteAnswer to take UnmarshalText into account.

One of my survey questions maps its answer to a struct field:

type Answers struct {
  Field SomeOtherStruct
}

func (s *SomeOtherStruct) UnmarshalText(data []byte) error {
   // code to convert text into struct
}

When using this struct as the survey output, it results in: Unable to convert from string to type struct.

But this conversion is already described in detail in my UnmarshalText function, which gets ignored now. It would be nice if the conversion code would check if a type implements TextUnmarshaler.

AlecAivazis commented 3 years ago

Hey @florisvdg - survey already supports marshaling/unmarshaling outof custom types as described here in the docs.

I'm going to close this to clean things up a bit but i will reopen if necessary