From 9ed715e74b237110221899d24cb9201250416c74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Hedenstr=C3=B6m?= <erik@hedenstroem.com> Date: Sun, 6 Feb 2022 23:33:55 +0100 Subject: [PATCH] Improved logic in client command. Updated docs. --- cmd/clients.go | 17 ++++++++++++++++- cmd/root.go | 2 +- docs/udm-query.md | 2 +- docs/udm-query_clients.md | 3 ++- docs/udm-query_completion.md | 2 +- docs/udm-query_completion_bash.md | 2 +- docs/udm-query_completion_fish.md | 2 +- docs/udm-query_completion_powershell.md | 2 +- docs/udm-query_completion_zsh.md | 2 +- docs/udm-query_devices.md | 2 +- docs/udm-query_dump.md | 2 +- docs/udm-query_list.md | 2 +- docs/udm-query_ping.md | 2 +- docs/udm-query_version.md | 2 +- 14 files changed, 30 insertions(+), 14 deletions(-) diff --git a/cmd/clients.go b/cmd/clients.go index a23cc17..574e031 100644 --- a/cmd/clients.go +++ b/cmd/clients.go @@ -9,6 +9,7 @@ import ( ) var fixedIp bool +var dynamicIp bool var clientsFilename string var clientsCmd = &cobra.Command{ @@ -19,7 +20,20 @@ var clientsCmd = &cobra.Command{ clients := ace.Collection("user") filter := bson.D{} if fixedIp { - filter = bson.D{{"use_fixedip", true}} + filter = bson.D{ + bson.E{"$and", bson.A{ + bson.M{"use_fixedip": bson.M{"$exists": true}}, + bson.M{"use_fixedip": bson.M{"$eq": true}}, + }}, + } + } + if dynamicIp { + filter = bson.D{ + bson.E{"$or", bson.A{ + bson.D{{"use_fixedip", bson.M{"$not": bson.M{"$exists": true}}}}, + bson.M{"use_fixedip": bson.M{"$ne": true}}, + }}, + } } docs, err := utils.FindDocuments(clients, filter) if err != nil { @@ -44,6 +58,7 @@ var clientsCmd = &cobra.Command{ func init() { clientsCmd.Flags().BoolVarP(&fixedIp, "fixed", "f", false, "Only show clients with fixed ip") + clientsCmd.Flags().BoolVarP(&dynamicIp, "dynamic", "d", false, "Only show clients with fixed ip") clientsCmd.Flags().StringVarP(&clientsFilename, "output", "o", "", "Write to file instead of stdout") clientsCmd.Flags().VarP(tableStyleFlag, "style", "s", "Table style") clientsCmd.Flags().VarP(renderModeFlag, "render", "r", "Output rendering mode") diff --git a/cmd/root.go b/cmd/root.go index ff1dfe8..788bfb3 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -62,7 +62,7 @@ func init() { cobra.OnInitialize(initEnv) RootCmd.PersistentFlags().StringP("address", "a", "192.168.1.1", "Address to the UDM SSH server") RootCmd.PersistentFlags().StringP("password", "p", "", "SSH password") - RootCmd.PersistentFlags().BoolVarP(&debug, "debug", "d", false, "Show debug output") + RootCmd.PersistentFlags().BoolVarP(&debug, "debug", "", false, "Show debug output") viper.SetEnvPrefix("SSH") viper.BindPFlag("ADDRESS", RootCmd.PersistentFlags().Lookup("address")) viper.BindPFlag("PASSWORD", RootCmd.PersistentFlags().Lookup("password")) diff --git a/docs/udm-query.md b/docs/udm-query.md index 87bbfd9..ee790b8 100644 --- a/docs/udm-query.md +++ b/docs/udm-query.md @@ -6,7 +6,7 @@ Tool to query Ubiquiti UniFi Dream Machines ``` -a, --address string Address to the UDM SSH server (default "192.168.1.1") - -d, --debug Show debug output + --debug Show debug output -h, --help help for udm-query -p, --password string SSH password ``` diff --git a/docs/udm-query_clients.md b/docs/udm-query_clients.md index 7a0e87c..8b5c347 100644 --- a/docs/udm-query_clients.md +++ b/docs/udm-query_clients.md @@ -9,6 +9,7 @@ udm-query clients [flags] ### Options ``` + -d, --dynamic Only show clients with fixed ip -f, --fixed Only show clients with fixed ip -h, --help help for clients -o, --output string Write to file instead of stdout @@ -20,7 +21,7 @@ udm-query clients [flags] ``` -a, --address string Address to the UDM SSH server (default "192.168.1.1") - -d, --debug Show debug output + --debug Show debug output -p, --password string SSH password ``` diff --git a/docs/udm-query_completion.md b/docs/udm-query_completion.md index 9c228d4..840e1c3 100644 --- a/docs/udm-query_completion.md +++ b/docs/udm-query_completion.md @@ -18,7 +18,7 @@ See each sub-command's help for details on how to use the generated script. ``` -a, --address string Address to the UDM SSH server (default "192.168.1.1") - -d, --debug Show debug output + --debug Show debug output -p, --password string SSH password ``` diff --git a/docs/udm-query_completion_bash.md b/docs/udm-query_completion_bash.md index 5bb9789..4040347 100644 --- a/docs/udm-query_completion_bash.md +++ b/docs/udm-query_completion_bash.md @@ -41,7 +41,7 @@ udm-query completion bash ``` -a, --address string Address to the UDM SSH server (default "192.168.1.1") - -d, --debug Show debug output + --debug Show debug output -p, --password string SSH password ``` diff --git a/docs/udm-query_completion_fish.md b/docs/udm-query_completion_fish.md index ea8dc42..08da55f 100644 --- a/docs/udm-query_completion_fish.md +++ b/docs/udm-query_completion_fish.md @@ -32,7 +32,7 @@ udm-query completion fish [flags] ``` -a, --address string Address to the UDM SSH server (default "192.168.1.1") - -d, --debug Show debug output + --debug Show debug output -p, --password string SSH password ``` diff --git a/docs/udm-query_completion_powershell.md b/docs/udm-query_completion_powershell.md index a282dbb..ed6d822 100644 --- a/docs/udm-query_completion_powershell.md +++ b/docs/udm-query_completion_powershell.md @@ -29,7 +29,7 @@ udm-query completion powershell [flags] ``` -a, --address string Address to the UDM SSH server (default "192.168.1.1") - -d, --debug Show debug output + --debug Show debug output -p, --password string SSH password ``` diff --git a/docs/udm-query_completion_zsh.md b/docs/udm-query_completion_zsh.md index cb826a6..359cd80 100644 --- a/docs/udm-query_completion_zsh.md +++ b/docs/udm-query_completion_zsh.md @@ -39,7 +39,7 @@ udm-query completion zsh [flags] ``` -a, --address string Address to the UDM SSH server (default "192.168.1.1") - -d, --debug Show debug output + --debug Show debug output -p, --password string SSH password ``` diff --git a/docs/udm-query_devices.md b/docs/udm-query_devices.md index 31c4473..765e189 100644 --- a/docs/udm-query_devices.md +++ b/docs/udm-query_devices.md @@ -19,7 +19,7 @@ udm-query devices [flags] ``` -a, --address string Address to the UDM SSH server (default "192.168.1.1") - -d, --debug Show debug output + --debug Show debug output -p, --password string SSH password ``` diff --git a/docs/udm-query_dump.md b/docs/udm-query_dump.md index 2bed474..a4b6fdb 100644 --- a/docs/udm-query_dump.md +++ b/docs/udm-query_dump.md @@ -20,7 +20,7 @@ udm-query dump [flags] <database> <collection> [fields] ``` -a, --address string Address to the UDM SSH server (default "192.168.1.1") - -d, --debug Show debug output + --debug Show debug output -p, --password string SSH password ``` diff --git a/docs/udm-query_list.md b/docs/udm-query_list.md index eb9c882..f1b1815 100644 --- a/docs/udm-query_list.md +++ b/docs/udm-query_list.md @@ -17,7 +17,7 @@ udm-query list [flags] ``` -a, --address string Address to the UDM SSH server (default "192.168.1.1") - -d, --debug Show debug output + --debug Show debug output -p, --password string SSH password ``` diff --git a/docs/udm-query_ping.md b/docs/udm-query_ping.md index dade553..aee6602 100644 --- a/docs/udm-query_ping.md +++ b/docs/udm-query_ping.md @@ -16,7 +16,7 @@ udm-query ping [flags] ``` -a, --address string Address to the UDM SSH server (default "192.168.1.1") - -d, --debug Show debug output + --debug Show debug output -p, --password string SSH password ``` diff --git a/docs/udm-query_version.md b/docs/udm-query_version.md index eff7008..b6408b4 100644 --- a/docs/udm-query_version.md +++ b/docs/udm-query_version.md @@ -16,7 +16,7 @@ udm-query version [flags] ``` -a, --address string Address to the UDM SSH server (default "192.168.1.1") - -d, --debug Show debug output + --debug Show debug output -p, --password string SSH password ``` -- GitLab