Recursive handling for command line flags

Every struct in a NodeConf with `lopt:"foo" set is now added as a
command-line flag with the RecursiveCreateFlags call. For maps a struct
with the key UNDEF is added so that it can be parsed out.

As the flags for the command-line need variables which hold the values,
for every map an element map[UNDEF] is added.  When now calling the
internal add, these map element can be filtered out and replace by the
given name. (e.g., --netname)

* rewrote node/profile add for recursive functions
* rewrote node/profile set for recursive functions
* rewrote node/profile list for recursive functions

Signed-off-by: Christian Goll <cgoll@suse.com>
This commit is contained in:
Christian Goll
2023-08-11 10:31:29 -06:00
committed by Jonathon Anderson
parent c55c5a2ac4
commit 45539a0d1f
29 changed files with 1346 additions and 714 deletions

View File

@@ -399,12 +399,15 @@ func GetByName(node interface{}, name string) (string, error) {
/*
Check if the Netdev is empty, so has no values set
*/
func (dev *NetDevs) Empty() bool {
if dev == nil {
func ObjectIsEmpty(obj interface{}) bool {
if obj == nil {
return true
}
varType := reflect.TypeOf(*dev)
varVal := reflect.ValueOf(*dev)
varType := reflect.TypeOf(obj)
varVal := reflect.ValueOf(obj)
if varType.Kind() == reflect.Ptr && !varVal.IsNil() {
return ObjectIsEmpty(varVal.Elem().Interface())
}
if varVal.IsZero() {
return true
}
@@ -418,6 +421,10 @@ func (dev *NetDevs) Empty() bool {
if len(varVal.Field(i).Interface().(map[string]string)) != 0 {
return false
}
} else if varType.Field(i).Type.Kind() == reflect.Ptr {
if !ObjectIsEmpty(varVal.Field(i).Interface()) {
return false
}
}
}
return true