Add sort support, can use every field
This commit is contained in:
10
cmd/root.go
10
cmd/root.go
@ -3,14 +3,14 @@ package cmd
|
||||
import (
|
||||
"os"
|
||||
"fmt"
|
||||
// "strings"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
const (
|
||||
version = "0.001"
|
||||
version = "0.02"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -81,7 +81,7 @@ func init() {
|
||||
listCmd.PersistentFlags().StringVarP(&gDisplayColumns, "outcol", "o", "JID,Name,Config.Release,Config.Ip4_addr,Running", "Show these columns in output")
|
||||
listCmd.PersistentFlags().BoolVarP(&gNoLineSep, "nolinesep", "l", false, "Do not display line separator between jails")
|
||||
listCmd.PersistentFlags().StringVarP(&gFilterJails, "filter", "f", "none", "Only display jails with these values. Ex: \"gocage list -f Config.Boot=1\" will only list started on boot jails")
|
||||
listCmd.PersistentFlags().StringVarP(&gSortFields, "sort", "s", "none", "Display jails sorted by field values. Ex: \"gocage list -s Config.Priority\" will sort jails by their start priority. NOT IMPLEMENTED YET")
|
||||
listCmd.PersistentFlags().StringVarP(&gSortFields, "sort", "s", "none", "Display jails sorted by field values. Ex: \"gocage list -s +Name,-Config.Priority\" will sort jails by their decreasing name, then increasing start priority. 3 critera max supported.")
|
||||
|
||||
// Now declare commands
|
||||
rootCmd.AddCommand(versionCmd)
|
||||
@ -124,6 +124,10 @@ func initConfig() {
|
||||
if listCmd.Flags().Lookup("sort") != nil && false == listCmd.Flags().Lookup("sort").Changed {
|
||||
gSortFields = viper.GetString("sort")
|
||||
}
|
||||
if len(strings.Split(gSortFields, ",")) > 3 {
|
||||
fmt.Printf("More than 3 sort criteria, this is not supported!\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func Execute() {
|
||||
|
Reference in New Issue
Block a user