chose listed jails, show real field name in header, sudo parameter, moved utilities into cmd/utils.go, started working on stop command
This commit is contained in:
42
cmd/list.go
42
cmd/list.go
@ -13,9 +13,8 @@ import (
|
||||
)
|
||||
|
||||
|
||||
var gJails []Jail
|
||||
|
||||
|
||||
// Recurse into structure, returning reflect.Value of wanted field.
|
||||
// Nested fields are named with a dot (ex "MyStruct.MyField")
|
||||
func getStructField(parentStruct interface{}, fieldName string) (reflect.Value, string) {
|
||||
v := reflect.ValueOf(parentStruct)
|
||||
|
||||
@ -42,19 +41,10 @@ func getStructField(parentStruct interface{}, fieldName string) (reflect.Value,
|
||||
}
|
||||
}
|
||||
|
||||
if false {
|
||||
if v.FieldByName(fieldName).IsValid() {
|
||||
log.Println(fmt.Sprintf("%s value: %s", fieldName, v.FieldByName(fieldName).Interface()))
|
||||
} else {
|
||||
log.Println(fmt.Sprintf("%s is invalid", fieldName))
|
||||
}
|
||||
}
|
||||
|
||||
return v, fieldName
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Pretty display of jails field
|
||||
Fields to show are given in a string array parameter
|
||||
Ex. : displayJails(["Name", "JID", "RootPath"])
|
||||
@ -152,8 +142,11 @@ func displayStructFields(jails []Jail, valsToDisplay []string) {
|
||||
if i == 0 {
|
||||
fmt.Printf("|")
|
||||
}
|
||||
/* Use vlsToDisplay to get real name (with "Config.")
|
||||
fmt.Printf(" %s", f.Name)
|
||||
for i := len(f.Name)+1 ; i < f.MaxLen+1 ; i++ {
|
||||
for i := len(f.Name)+1 ; i < f.MaxLen+1 ; i++ { */
|
||||
fmt.Printf(" %s", valsToDisplay[i])
|
||||
for i := len(valsToDisplay[i])+1 ; i < f.MaxLen+1 ; i++ {
|
||||
fmt.Printf(" ")
|
||||
}
|
||||
fmt.Printf(" |")
|
||||
@ -184,12 +177,31 @@ func displayStructFields(jails []Jail, valsToDisplay []string) {
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
|
||||
func listJails(args []string) {
|
||||
|
||||
/* Get Jails from datastores. Store config and running metadata into gJails global var */
|
||||
func listJails(args []string, display bool) {
|
||||
fields := []string{"JID", "Name", "Config.Release", "Config.Ip4_addr", "RootPath", "Running", "Config.Jail_zfs", "Config.Jail_zfs_dataset"}
|
||||
|
||||
for _, d := range viper.GetStringSlice("datastore") {
|
||||
listJailsFromDatastore(d)
|
||||
}
|
||||
|
||||
displayStructFields(gJails, []string{"JID", "Name", "Config.Release", "Config.Ip4_addr", "RootPath"})
|
||||
if display {
|
||||
if len(args) > 0 {
|
||||
var js []Jail
|
||||
for _, a := range args {
|
||||
for _, j := range gJails {
|
||||
if j.Name == a {
|
||||
js = append(js, j)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
displayStructFields(js, fields)
|
||||
} else {
|
||||
displayStructFields(gJails, fields)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user