added hangling of map[string]*struct
This commit is contained in:
@@ -36,7 +36,6 @@ var (
|
||||
SetKernelOverride string
|
||||
SetNetName string
|
||||
SetNetDev string
|
||||
SetIpaddr string
|
||||
SetNetmask string
|
||||
SetGateway string
|
||||
SetHwaddr string
|
||||
@@ -138,7 +137,6 @@ func init() {
|
||||
}
|
||||
baseCmd.PersistentFlags().StringVarP(&SetNetName, "netname", "n", "default", "Define the network name to configure")
|
||||
baseCmd.PersistentFlags().StringVarP(&SetNetDev, "netdev", "N", "", "Set the node's network device")
|
||||
baseCmd.PersistentFlags().StringVarP(&SetIpaddr, "ipaddr", "I", "", "Set the node's network device IP address")
|
||||
baseCmd.PersistentFlags().StringVarP(&SetNetmask, "netmask", "M", "", "Set the node's network device netmask")
|
||||
baseCmd.PersistentFlags().StringVarP(&SetGateway, "gateway", "G", "", "Set the node's network device gateway")
|
||||
baseCmd.PersistentFlags().StringVarP(&SetHwaddr, "hwaddr", "H", "", "Set the node's network device HW address")
|
||||
|
||||
@@ -69,7 +69,7 @@ type NetDevs struct {
|
||||
OnBoot string `yaml:"onboot,omitempty"`
|
||||
Device string `yaml:"device,omitempty"`
|
||||
Hwaddr string `yaml:"hwaddr,omitempty"`
|
||||
Ipaddr string `yaml:"ipaddr,omitempty"`
|
||||
Ipaddr string `yaml:"ipaddr,omitempty" comment:"IPv4 address" sopt:"I" lopt:"ipaddr"`
|
||||
IpCIDR string `yaml:"ipcidr,omitempty"`
|
||||
Ipaddr6 string `yaml:"ip6addr,omitempty"`
|
||||
Prefix string `yaml:"prefix,omitempty"`
|
||||
|
||||
@@ -424,14 +424,24 @@ func (baseCmd *CobraCommand) CreateFlags(theStruct interface{}) map[string]*stri
|
||||
fmt.Printf("%s: field.Kind() == %s\n", field.Name, field.Type.Kind())
|
||||
if field.Type.Kind() == reflect.Ptr {
|
||||
a := structVal.Field(i).Elem().Interface()
|
||||
fmt.Println(structVal.Field(i).Elem())
|
||||
subStruct := baseCmd.CreateFlags(a)
|
||||
for key, val := range subStruct {
|
||||
optionsMap[field.Name+"."+key] = val
|
||||
}
|
||||
|
||||
} else if field.Type.Kind() == reflect.Map {
|
||||
// Just check for network map
|
||||
fmt.Println(reflect.TypeOf(structVal.Field(i).Elem()))
|
||||
// check the type of map
|
||||
mapType := field.Type.Elem()
|
||||
if mapType.Kind() == reflect.Ptr {
|
||||
//a := reflect.ValueOf((mapType.Elem())) node.NetDevs
|
||||
subMap := baseCmd.CreateFlags(reflect.New(mapType.Elem()).Elem().Interface())
|
||||
for key, val := range subMap {
|
||||
optionsMap[field.Name+"."+key] = val
|
||||
}
|
||||
} else {
|
||||
fmt.Println(mapType)
|
||||
}
|
||||
|
||||
} else if field.Tag.Get("comment") != "" {
|
||||
var newStr string
|
||||
|
||||
Reference in New Issue
Block a user