Add filter option, update Readme
This commit is contained in:
12
cmd/root.go
12
cmd/root.go
@ -20,6 +20,8 @@ var (
|
||||
|
||||
gConfigFile string
|
||||
gDisplayColumns string
|
||||
gFilterJails string
|
||||
gSortFields string
|
||||
gNoLineSep bool
|
||||
|
||||
|
||||
@ -73,11 +75,13 @@ func init() {
|
||||
|
||||
// Global switches
|
||||
rootCmd.PersistentFlags().StringVarP(&gConfigFile, "config", "c", "/usr/local/etc/gocage.conf.yml", "GoCage configuration file")
|
||||
rootCmd.PersistentFlags().BoolVarP(&gUseSudo, "sudo", "s", false, "Use sudo to run commands")
|
||||
rootCmd.PersistentFlags().BoolVarP(&gUseSudo, "sudo", "u", false, "Use sudo to run commands")
|
||||
|
||||
// Command dependant switches
|
||||
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")
|
||||
|
||||
// Now declare commands
|
||||
rootCmd.AddCommand(versionCmd)
|
||||
@ -114,6 +118,12 @@ func initConfig() {
|
||||
if listCmd.Flags().Lookup("nolinesep") != nil && false == listCmd.Flags().Lookup("nolinesep").Changed {
|
||||
gNoLineSep = viper.GetBool("nolinesep")
|
||||
}
|
||||
if listCmd.Flags().Lookup("filter") != nil && false == listCmd.Flags().Lookup("filter").Changed {
|
||||
gFilterJails = viper.GetString("filter")
|
||||
}
|
||||
if listCmd.Flags().Lookup("sort") != nil && false == listCmd.Flags().Lookup("sort").Changed {
|
||||
gSortFields = viper.GetString("sort")
|
||||
}
|
||||
}
|
||||
|
||||
func Execute() {
|
||||
|
||||
Reference in New Issue
Block a user