github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/internal/runners/hello/text_example.go (about) 1 package hello 2 3 import ( 4 "github.com/ActiveState/cli/internal/errs" 5 ) 6 7 // Text represents an implementation of captain.FlagMarshaler. It is a trivial 8 // example, and does not do very much interesting except provide a way to check 9 // if it has been set by the user. 10 type Text struct { 11 Value string 12 isSet bool 13 } 14 15 // Set implements the captain flagmarshaler interface. 16 func (t *Text) Set(v string) error { 17 if t == nil { 18 return errs.New("cannot set nil value") 19 } 20 t.Value, t.isSet = v, true 21 return nil 22 } 23 24 // String implements the fmt.Stringer and flagmarshaler interfaces. 25 func (t *Text) String() string { 26 if t == nil { 27 return "" 28 } 29 return t.Value 30 } 31 32 // Type implements the flagmarshaler interface. 33 func (t *Text) Type() string { 34 return "text" 35 } 36 37 func (ns *Text) IsSet() bool { 38 return ns.isSet 39 }