Use getJailFromArray so we can handle same name jails
This commit is contained in:
parent
e13437b79e
commit
9b90f9c812
@ -10,13 +10,18 @@ import (
|
||||
|
||||
func GetJailProperties(args []string) {
|
||||
var props []string
|
||||
var jail Jail
|
||||
var jail *Jail
|
||||
var err error
|
||||
|
||||
if len(args) > 0 {
|
||||
for i, a := range args {
|
||||
// Last arg is the jail name
|
||||
if i == len(args)-1 {
|
||||
jail.Name = a
|
||||
jail, err = getJailFromArray(a, gJails)
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %s\n", err.Error())
|
||||
return
|
||||
}
|
||||
} else {
|
||||
props = append(props, a)
|
||||
}
|
||||
@ -28,15 +33,15 @@ func GetJailProperties(args []string) {
|
||||
fmt.Printf("Error\n")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if isStringInArray(props, "all") {
|
||||
var result []string
|
||||
result = getStructFieldNames(jail, result, "")
|
||||
result = getStructFieldNames(*jail, result, "")
|
||||
props = result
|
||||
}
|
||||
|
||||
for _, p := range props {
|
||||
v, err := getJailProperty(&jail, p)
|
||||
v, err := getJailProperty(jail, p)
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %s\n", err.Error())
|
||||
return
|
||||
@ -47,27 +52,23 @@ func GetJailProperties(args []string) {
|
||||
}
|
||||
|
||||
func getJailProperty(jail *Jail, propName string) (string, error) {
|
||||
for i, j := range gJails {
|
||||
if j.Name == jail.Name {
|
||||
val, _, err := getStructFieldValue(&gJails[i], propName)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
switch val.Kind() {
|
||||
case reflect.String:
|
||||
return val.String(), nil
|
||||
case reflect.Int:
|
||||
return strconv.FormatInt(val.Int(), 10), nil
|
||||
case reflect.Bool:
|
||||
return strconv.FormatBool(val.Bool()), nil
|
||||
default:
|
||||
return "", errors.New(fmt.Sprintf("Error: Unknown type for property %s: %s\n", propName, val.Kind()))
|
||||
}
|
||||
}
|
||||
val, _, err := getStructFieldValue(jail, propName)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return "", errors.New(fmt.Sprintf("Jail not found: %s", jail.Name))
|
||||
switch val.Kind() {
|
||||
case reflect.String:
|
||||
return val.String(), nil
|
||||
case reflect.Int:
|
||||
return strconv.FormatInt(val.Int(), 10), nil
|
||||
case reflect.Bool:
|
||||
return strconv.FormatBool(val.Bool()), nil
|
||||
default:
|
||||
return "", errors.New(fmt.Sprintf("Error: Unknown type for property %s: %s\n", propName, val.Kind()))
|
||||
}
|
||||
|
||||
return "", errors.New("Unknown error in getJailProperty")
|
||||
}
|
||||
|
||||
func SetJailProperties(args []string) {
|
||||
|
Loading…
Reference in New Issue
Block a user