Add command "list properties" so we can get all internal properties to sort, filter, or set jail properties
This commit is contained in:
36
cmd/list.go
36
cmd/list.go
@ -296,6 +296,42 @@ func displayStructFields(jails []Jail, valsToDisplay []string) {
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
|
||||
/*
|
||||
* Display struct attributes name for a given struct.
|
||||
* Recurse into struct attributes of type struct
|
||||
* Used to show user jail properties
|
||||
*/
|
||||
func getStructFieldNames(parentStruct interface{}, result []string, prefix string) []string {
|
||||
v := reflect.ValueOf(parentStruct)
|
||||
|
||||
for i := 0 ; i < v.NumField() ; i++ {
|
||||
if v.Type().Field(i).Type.Kind() == reflect.Struct {
|
||||
result = getStructFieldNames(v.Field(i).Interface(), result, v.Type().Field(i).Name)
|
||||
} else {
|
||||
if len(prefix) > 0 {
|
||||
result = append(result, fmt.Sprintf("%s.%s", prefix, v.Type().Field(i).Name))
|
||||
} else {
|
||||
result = append(result, v.Type().Field(i).Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func ListJailsProps(args []string) {
|
||||
var conf Jail
|
||||
var jailconf JailConfig
|
||||
var result []string
|
||||
|
||||
conf.Config = jailconf
|
||||
|
||||
result = getStructFieldNames(conf, result, "")
|
||||
|
||||
for _, f := range result {
|
||||
fmt.Printf("%s\n", f)
|
||||
}
|
||||
}
|
||||
|
||||
/* Get Jails from datastores. Store config and running metadata into gJails global var */
|
||||
func ListJails(args []string, display bool) {
|
||||
|
||||
Reference in New Issue
Block a user