Add command "list properties" so we can get all internal properties to sort, filter, or set jail properties
This commit is contained in:
parent
8d18bfe55d
commit
f1c4fd960d
36
cmd/list.go
36
cmd/list.go
@ -296,6 +296,42 @@ func displayStructFields(jails []Jail, valsToDisplay []string) {
|
|||||||
fmt.Printf("\n")
|
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 */
|
/* Get Jails from datastores. Store config and running metadata into gJails global var */
|
||||||
func ListJails(args []string, display bool) {
|
func ListJails(args []string, display bool) {
|
||||||
|
15
cmd/root.go
15
cmd/root.go
@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
gVersion = "0.022a"
|
gVersion = "0.022b"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -63,10 +63,20 @@ ex: gocage list srv-db srv-web`,
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
listPropsCmd = &cobra.Command{
|
||||||
|
Use: "properties",
|
||||||
|
Short: "Print jails properties",
|
||||||
|
Long: "Display jails properties. You can use properties to filter, get or set them.",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
ListJailsProps(args)
|
||||||
|
cleanAfterRun()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
stopCmd = &cobra.Command{
|
stopCmd = &cobra.Command{
|
||||||
Use: "stop",
|
Use: "stop",
|
||||||
Short: "stop jail",
|
Short: "stop jail",
|
||||||
Long: `shutdown jail`,
|
Long: "shutdown jail",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
// Get the inventory
|
// Get the inventory
|
||||||
ListJails(args, false)
|
ListJails(args, false)
|
||||||
@ -105,6 +115,7 @@ func init() {
|
|||||||
// Now declare commands
|
// Now declare commands
|
||||||
rootCmd.AddCommand(versionCmd)
|
rootCmd.AddCommand(versionCmd)
|
||||||
rootCmd.AddCommand(listCmd)
|
rootCmd.AddCommand(listCmd)
|
||||||
|
listCmd.AddCommand(listPropsCmd)
|
||||||
rootCmd.AddCommand(stopCmd)
|
rootCmd.AddCommand(stopCmd)
|
||||||
rootCmd.AddCommand(startCmd)
|
rootCmd.AddCommand(startCmd)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user