WIP on start, go fmt on *
This commit is contained in:
@ -1,17 +1,17 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetJailProperties(args []string) {
|
||||
var props []string
|
||||
var jail Jail
|
||||
|
||||
|
||||
if len(args) > 0 {
|
||||
for i, a := range args {
|
||||
// Last arg is the jail name
|
||||
@ -21,20 +21,20 @@ func GetJailProperties(args []string) {
|
||||
props = append(props, a)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if len(jail.Name) == 0 || len(args) == 0 {
|
||||
// TODO : Show help
|
||||
fmt.Printf("Error\n")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if isStringInArray(props, "all") {
|
||||
var result []string
|
||||
result = getStructFieldNames(jail, result, "")
|
||||
props = result
|
||||
}
|
||||
|
||||
|
||||
for _, p := range props {
|
||||
v, err := getJailProperty(&jail, p)
|
||||
if err != nil {
|
||||
@ -53,32 +53,32 @@ func getJailProperty(jail *Jail, propName string) (string, error) {
|
||||
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()))
|
||||
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))
|
||||
}
|
||||
|
||||
func SetJailProperties(args []string) {
|
||||
type properties struct {
|
||||
name string
|
||||
value string
|
||||
name string
|
||||
value string
|
||||
}
|
||||
|
||||
|
||||
var jail Jail
|
||||
var props []properties
|
||||
|
||||
|
||||
if len(args) > 0 {
|
||||
for i, a := range args {
|
||||
// This is the jail name
|
||||
@ -96,14 +96,14 @@ func SetJailProperties(args []string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if len(jail.Name) == 0 || len(args) == 0 {
|
||||
// TODO : Show help
|
||||
fmt.Printf("Error\n")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
// Get jail by index to modify it
|
||||
for i, _ := range gJails {
|
||||
if gJails[i].Name == jail.Name {
|
||||
@ -120,5 +120,3 @@ func SetJailProperties(args []string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user