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) {
|
func GetJailProperties(args []string) {
|
||||||
var props []string
|
var props []string
|
||||||
var jail Jail
|
var jail *Jail
|
||||||
|
var err error
|
||||||
|
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
for i, a := range args {
|
for i, a := range args {
|
||||||
// Last arg is the jail name
|
// Last arg is the jail name
|
||||||
if i == len(args)-1 {
|
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 {
|
} else {
|
||||||
props = append(props, a)
|
props = append(props, a)
|
||||||
}
|
}
|
||||||
@ -31,12 +36,12 @@ func GetJailProperties(args []string) {
|
|||||||
|
|
||||||
if isStringInArray(props, "all") {
|
if isStringInArray(props, "all") {
|
||||||
var result []string
|
var result []string
|
||||||
result = getStructFieldNames(jail, result, "")
|
result = getStructFieldNames(*jail, result, "")
|
||||||
props = result
|
props = result
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, p := range props {
|
for _, p := range props {
|
||||||
v, err := getJailProperty(&jail, p)
|
v, err := getJailProperty(jail, p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error: %s\n", err.Error())
|
fmt.Printf("Error: %s\n", err.Error())
|
||||||
return
|
return
|
||||||
@ -47,27 +52,23 @@ func GetJailProperties(args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getJailProperty(jail *Jail, propName string) (string, error) {
|
func getJailProperty(jail *Jail, propName string) (string, error) {
|
||||||
for i, j := range gJails {
|
val, _, err := getStructFieldValue(jail, propName)
|
||||||
if j.Name == jail.Name {
|
if err != nil {
|
||||||
val, _, err := getStructFieldValue(&gJails[i], propName)
|
return "", err
|
||||||
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()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
func SetJailProperties(args []string) {
|
||||||
|
Loading…
Reference in New Issue
Block a user