ListJailsProps() : Replace unused args with format

This commit is contained in:
yo 2024-09-05 09:16:32 +02:00
parent 4cc1c476aa
commit 9d7db268cc

View File

@ -15,23 +15,37 @@ import (
* List all properties a jail have, with their internal name
* Only print properties name. To get name & values, use GetJailProperties()
*******************************************************************************/
func ListJailsProps(args []string) {
func ListJailsProps(format string) (string, error) {
var conf Jail
var result []string
var props []string
var out string
// Mandatory constructor to init default values
jailconf, err := NewJailConfig()
if err != nil {
fmt.Printf("Error allocating JailConfig: %s\n", err.Error())
return
return out, err
}
conf.Config = jailconf
result = getStructFieldNames(conf, result, "")
props = getStructFieldNames(conf, props, "")
for _, f := range result {
fmt.Printf("%s\n", f)
if format == "json" {
out = "{\"properties\":["
for i, p := range props {
out += fmt.Sprintf("\"%s\"", p)
if i < len(props) - 1 {
out += ","
}
}
out += "]}"
} else {
for _, p := range props {
out += fmt.Sprintf("%s\n", p)
}
}
return out, nil
}
/********************************************************************************