lang: types: Add simple parsing of net.HardwareAddr

If we want to use special struct types from our CLI parser, we also need
to be able to both identify, and convert them to our language type and
value representations.

For as long as we don't have fancier types in our language, these should
both be strings. Tests and extensions to these additions are welcome!
This commit is contained in:
James Shubin
2024-03-05 21:39:43 -05:00
parent 4140492d56
commit b85f81d529
2 changed files with 18 additions and 0 deletions

View File

@@ -31,6 +31,7 @@ package types
import (
"fmt"
"net"
"reflect"
"strings"
@@ -184,6 +185,14 @@ func ConfigurableTypeOf(t reflect.Type, opts ...TypeOfOption) (*Type, error) {
kind = typ.Kind()
}
// Special cases:
if reflect.TypeOf(net.HardwareAddr{}) == typ {
return &Type{
Kind: KindStr,
}, nil
}
// TODO: net/url.URL, time.Duration, etc. Note: avoid net/mail.Address
switch kind { // match on destination field kind
case reflect.Bool:
return &Type{