diff --git a/cmd/clients.go b/cmd/clients.go index f5f325895361eb2d4d835958a68a772f8504ca8d..a23cc17e4cbd7fff7d035162f9f2a07f68bb90fd 100644 --- a/cmd/clients.go +++ b/cmd/clients.go @@ -9,6 +9,7 @@ import ( ) var fixedIp bool +var clientsFilename string var clientsCmd = &cobra.Command{ Use: "clients", @@ -28,8 +29,8 @@ var clientsCmd = &cobra.Command{ style := utils.TableStyleMap[tableStyle] output := utils.RenderDocuments(docs, []string{"fixed_ip", "name", "hostname", "mac"}, renderMode, style) file := os.Stdout - if filename != "" { - file, err = os.Create(filename) + if clientsFilename != "" { + file, err = os.Create(clientsFilename) if err != nil { return err } @@ -38,11 +39,12 @@ var clientsCmd = &cobra.Command{ file.WriteString("\n") return nil }, + DisableAutoGenTag: true, } func init() { clientsCmd.Flags().BoolVarP(&fixedIp, "fixed", "f", false, "Only show clients with fixed ip") - clientsCmd.Flags().StringVarP(&filename, "output", "o", "", "Write to file instead of stdout") + 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") RootCmd.AddCommand(clientsCmd) diff --git a/cmd/devices.go b/cmd/devices.go index 43ccbe151a7ca5b66873274368cf51d2ce421c0c..2b17be838e68f34325a405db6ba0e931df43af10 100644 --- a/cmd/devices.go +++ b/cmd/devices.go @@ -7,6 +7,8 @@ import ( "gitlab.hedenstroem.com/go/udm-query/utils" ) +var devicesFilename string + var devicesCmd = &cobra.Command{ Use: "devices", Short: "Display UniFi devices", @@ -21,8 +23,8 @@ var devicesCmd = &cobra.Command{ style := utils.TableStyleMap[tableStyle] output := utils.RenderDocuments(docs, []string{"fixed_ip", "name", "hostname", "mac"}, renderMode, style) file := os.Stdout - if filename != "" { - file, err = os.Create(filename) + if devicesFilename != "" { + file, err = os.Create(devicesFilename) if err != nil { return err } @@ -31,10 +33,11 @@ var devicesCmd = &cobra.Command{ file.WriteString("\n") return nil }, + DisableAutoGenTag: true, } func init() { - devicesCmd.Flags().StringVarP(&filename, "output", "o", "", "Write to file instead of stdout") + devicesCmd.Flags().StringVarP(&devicesFilename, "output", "o", "", "Write to file instead of stdout") devicesCmd.Flags().VarP(tableStyleFlag, "style", "s", "Table style") devicesCmd.Flags().VarP(renderModeFlag, "render", "r", "Output rendering mode") RootCmd.AddCommand(devicesCmd) diff --git a/cmd/docs.go b/cmd/docs.go new file mode 100644 index 0000000000000000000000000000000000000000..346476fa75871db0a80d2492c5d3482f97df7373 --- /dev/null +++ b/cmd/docs.go @@ -0,0 +1,27 @@ +package cmd + +import ( + "os" + + "github.com/spf13/cobra" + "github.com/spf13/cobra/doc" +) + +var docsPath string + +var docsCmd = &cobra.Command{ + Use: "docs", + Short: "Generate markdown documentation", + RunE: func(cmd *cobra.Command, args []string) (err error) { + if err = os.MkdirAll(docsPath, os.ModePerm); err == nil { + err = doc.GenMarkdownTree(RootCmd, docsPath) + } + return + }, + Hidden: true, +} + +func init() { + RootCmd.AddCommand(docsCmd) + docsCmd.Flags().StringVarP(&docsPath, "output", "o", "./docs", "Output path") +} diff --git a/cmd/dump.go b/cmd/dump.go index a86fde057f74fb9b1c7b30201833c6390392f537..16f34000985f375b69f9c9b13963fbe68da0054d 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -10,6 +10,7 @@ import ( ) var table bool +var dumpFilename string var dumpCmd = &cobra.Command{ Use: "dump [flags] <database> <collection> [fields]", @@ -28,8 +29,8 @@ var dumpCmd = &cobra.Command{ return err } file := os.Stdout - if filename != "" { - file, err = os.Create(filename) + if dumpFilename != "" { + file, err = os.Create(dumpFilename) if err != nil { return err } @@ -45,11 +46,12 @@ var dumpCmd = &cobra.Command{ file.WriteString("\n") return nil }, + DisableAutoGenTag: true, } func init() { dumpCmd.Flags().BoolVarP(&table, "table", "t", false, "Output as table") - dumpCmd.Flags().StringVarP(&filename, "output", "o", "", "Write to file instead of stdout") + dumpCmd.Flags().StringVarP(&dumpFilename, "output", "o", "", "Write to file instead of stdout") dumpCmd.Flags().VarP(tableStyleFlag, "style", "s", "Table style") dumpCmd.Flags().VarP(renderModeFlag, "render", "r", "Output rendering mode") RootCmd.AddCommand(dumpCmd) diff --git a/cmd/list.go b/cmd/list.go index 8e7706bf4f391414778b560d203471c58953aad1..f090890f7335ed8a80090728afd9b1a917bfa851 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -41,6 +41,7 @@ var listCmd = &cobra.Command{ l.Render() return nil }, + DisableAutoGenTag: true, } func init() { diff --git a/cmd/ping.go b/cmd/ping.go index 80381363741a464eea128722514745048744f3bb..b8be159046deb3d6d318435e9b83e8e6aace5ba6 100644 --- a/cmd/ping.go +++ b/cmd/ping.go @@ -11,13 +11,13 @@ import ( var pingCmd = &cobra.Command{ Use: "ping", Short: "Ping the database", - Long: `Sends no-op command to check if the database is responding to commands`, RunE: func(cmd *cobra.Command, args []string) (err error) { if err = client.Ping(context.TODO(), readpref.Primary()); err == nil { fmt.Println("success") } return }, + DisableAutoGenTag: true, } func init() { diff --git a/cmd/root.go b/cmd/root.go index fd6120ee9cd942837bed61c4802ccf905dd5561d..843d77bb385a6f2cf71abfdc6a2bf49ccec62910 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -20,7 +20,6 @@ import ( var ( debug bool client *mongo.Client - filename string renderMode utils.RenderMode tableStyle utils.TableStyle listStyle utils.ListStyle @@ -30,8 +29,8 @@ var ( ) var RootCmd = &cobra.Command{ - Use: "udm-query", - Long: `Tool to query Ubiquiti UniFi Dream Machines`, + Use: "udm-query", + Short: "Tool to query Ubiquiti UniFi Dream Machines", PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) { tunnel := ssh.NewSSHTunnel( viper.GetString("ADDRESS"), @@ -50,6 +49,7 @@ var RootCmd = &cobra.Command{ PersistentPostRunE: func(cmd *cobra.Command, args []string) error { return client.Disconnect(context.TODO()) }, + DisableAutoGenTag: true, } func Execute() { diff --git a/cmd/version.go b/cmd/version.go index 70976114fca41b939db31812ddaaf7323bf95dd3..9401b051c388b7e4975991e46e7a9295bf32576e 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -13,6 +13,7 @@ var versionCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { fmt.Println(constant.Version) }, + DisableAutoGenTag: true, } func init() { diff --git a/docs/udm-query.md b/docs/udm-query.md new file mode 100644 index 0000000000000000000000000000000000000000..87bbfd988c0ad82d84fb45323f440f4eaeb710b6 --- /dev/null +++ b/docs/udm-query.md @@ -0,0 +1,23 @@ +## udm-query + +Tool to query Ubiquiti UniFi Dream Machines + +### Options + +``` + -a, --address string Address to the UDM SSH server (default "192.168.1.1") + -d, --debug Show debug output + -h, --help help for udm-query + -p, --password string SSH password +``` + +### SEE ALSO + +* [udm-query clients](udm-query_clients.md) - Display client devices +* [udm-query completion](udm-query_completion.md) - Generate the autocompletion script for the specified shell +* [udm-query devices](udm-query_devices.md) - Display UniFi devices +* [udm-query dump](udm-query_dump.md) - Export collection to JSON or a table +* [udm-query list](udm-query_list.md) - List databases and their collections +* [udm-query ping](udm-query_ping.md) - Ping the database +* [udm-query version](udm-query_version.md) - Display udm-query version + diff --git a/docs/udm-query_clients.md b/docs/udm-query_clients.md new file mode 100644 index 0000000000000000000000000000000000000000..7a0e87c20d5bc33d19829f9a4ab6607663313415 --- /dev/null +++ b/docs/udm-query_clients.md @@ -0,0 +1,30 @@ +## udm-query clients + +Display client devices + +``` +udm-query clients [flags] +``` + +### Options + +``` + -f, --fixed Only show clients with fixed ip + -h, --help help for clients + -o, --output string Write to file instead of stdout + -r, --render string Output rendering mode (default "table") + -s, --style string Table style (default "default") +``` + +### Options inherited from parent commands + +``` + -a, --address string Address to the UDM SSH server (default "192.168.1.1") + -d, --debug Show debug output + -p, --password string SSH password +``` + +### SEE ALSO + +* [udm-query](udm-query.md) - Tool to query Ubiquiti UniFi Dream Machines + diff --git a/docs/udm-query_completion.md b/docs/udm-query_completion.md new file mode 100644 index 0000000000000000000000000000000000000000..9c228d4a7d777b4669ecb664b31d52a885df9603 --- /dev/null +++ b/docs/udm-query_completion.md @@ -0,0 +1,32 @@ +## udm-query completion + +Generate the autocompletion script for the specified shell + +### Synopsis + +Generate the autocompletion script for udm-query for the specified shell. +See each sub-command's help for details on how to use the generated script. + + +### Options + +``` + -h, --help help for completion +``` + +### Options inherited from parent commands + +``` + -a, --address string Address to the UDM SSH server (default "192.168.1.1") + -d, --debug Show debug output + -p, --password string SSH password +``` + +### SEE ALSO + +* [udm-query](udm-query.md) - Tool to query Ubiquiti UniFi Dream Machines +* [udm-query completion bash](udm-query_completion_bash.md) - Generate the autocompletion script for bash +* [udm-query completion fish](udm-query_completion_fish.md) - Generate the autocompletion script for fish +* [udm-query completion powershell](udm-query_completion_powershell.md) - Generate the autocompletion script for powershell +* [udm-query completion zsh](udm-query_completion_zsh.md) - Generate the autocompletion script for zsh + diff --git a/docs/udm-query_completion_bash.md b/docs/udm-query_completion_bash.md new file mode 100644 index 0000000000000000000000000000000000000000..5bb9789411a0e6f060620232b173b641a0bb3e52 --- /dev/null +++ b/docs/udm-query_completion_bash.md @@ -0,0 +1,51 @@ +## udm-query completion bash + +Generate the autocompletion script for bash + +### Synopsis + +Generate the autocompletion script for the bash shell. + +This script depends on the 'bash-completion' package. +If it is not installed already, you can install it via your OS's package manager. + +To load completions in your current shell session: + + source <(udm-query completion bash) + +To load completions for every new session, execute once: + +#### Linux: + + udm-query completion bash > /etc/bash_completion.d/udm-query + +#### macOS: + + udm-query completion bash > /usr/local/etc/bash_completion.d/udm-query + +You will need to start a new shell for this setup to take effect. + + +``` +udm-query completion bash +``` + +### Options + +``` + -h, --help help for bash + --no-descriptions disable completion descriptions +``` + +### Options inherited from parent commands + +``` + -a, --address string Address to the UDM SSH server (default "192.168.1.1") + -d, --debug Show debug output + -p, --password string SSH password +``` + +### SEE ALSO + +* [udm-query completion](udm-query_completion.md) - Generate the autocompletion script for the specified shell + diff --git a/docs/udm-query_completion_fish.md b/docs/udm-query_completion_fish.md new file mode 100644 index 0000000000000000000000000000000000000000..ea8dc423099c727a369bccb2340743dc717add12 --- /dev/null +++ b/docs/udm-query_completion_fish.md @@ -0,0 +1,42 @@ +## udm-query completion fish + +Generate the autocompletion script for fish + +### Synopsis + +Generate the autocompletion script for the fish shell. + +To load completions in your current shell session: + + udm-query completion fish | source + +To load completions for every new session, execute once: + + udm-query completion fish > ~/.config/fish/completions/udm-query.fish + +You will need to start a new shell for this setup to take effect. + + +``` +udm-query completion fish [flags] +``` + +### Options + +``` + -h, --help help for fish + --no-descriptions disable completion descriptions +``` + +### Options inherited from parent commands + +``` + -a, --address string Address to the UDM SSH server (default "192.168.1.1") + -d, --debug Show debug output + -p, --password string SSH password +``` + +### SEE ALSO + +* [udm-query completion](udm-query_completion.md) - Generate the autocompletion script for the specified shell + diff --git a/docs/udm-query_completion_powershell.md b/docs/udm-query_completion_powershell.md new file mode 100644 index 0000000000000000000000000000000000000000..a282dbb1cf71662dc8555b2599765349d3afc258 --- /dev/null +++ b/docs/udm-query_completion_powershell.md @@ -0,0 +1,39 @@ +## udm-query completion powershell + +Generate the autocompletion script for powershell + +### Synopsis + +Generate the autocompletion script for powershell. + +To load completions in your current shell session: + + udm-query completion powershell | Out-String | Invoke-Expression + +To load completions for every new session, add the output of the above command +to your powershell profile. + + +``` +udm-query completion powershell [flags] +``` + +### Options + +``` + -h, --help help for powershell + --no-descriptions disable completion descriptions +``` + +### Options inherited from parent commands + +``` + -a, --address string Address to the UDM SSH server (default "192.168.1.1") + -d, --debug Show debug output + -p, --password string SSH password +``` + +### SEE ALSO + +* [udm-query completion](udm-query_completion.md) - Generate the autocompletion script for the specified shell + diff --git a/docs/udm-query_completion_zsh.md b/docs/udm-query_completion_zsh.md new file mode 100644 index 0000000000000000000000000000000000000000..cb826a66e5d53cb4248bbcafc5f31b92b1c862ca --- /dev/null +++ b/docs/udm-query_completion_zsh.md @@ -0,0 +1,49 @@ +## udm-query completion zsh + +Generate the autocompletion script for zsh + +### Synopsis + +Generate the autocompletion script for the zsh shell. + +If shell completion is not already enabled in your environment you will need +to enable it. You can execute the following once: + + echo "autoload -U compinit; compinit" >> ~/.zshrc + +To load completions for every new session, execute once: + +#### Linux: + + udm-query completion zsh > "${fpath[1]}/_udm-query" + +#### macOS: + + udm-query completion zsh > /usr/local/share/zsh/site-functions/_udm-query + +You will need to start a new shell for this setup to take effect. + + +``` +udm-query completion zsh [flags] +``` + +### Options + +``` + -h, --help help for zsh + --no-descriptions disable completion descriptions +``` + +### Options inherited from parent commands + +``` + -a, --address string Address to the UDM SSH server (default "192.168.1.1") + -d, --debug Show debug output + -p, --password string SSH password +``` + +### SEE ALSO + +* [udm-query completion](udm-query_completion.md) - Generate the autocompletion script for the specified shell + diff --git a/docs/udm-query_devices.md b/docs/udm-query_devices.md new file mode 100644 index 0000000000000000000000000000000000000000..31c4473b633ff1a1ab900f831638951a8b4bcd36 --- /dev/null +++ b/docs/udm-query_devices.md @@ -0,0 +1,29 @@ +## udm-query devices + +Display UniFi devices + +``` +udm-query devices [flags] +``` + +### Options + +``` + -h, --help help for devices + -o, --output string Write to file instead of stdout + -r, --render string Output rendering mode (default "table") + -s, --style string Table style (default "default") +``` + +### Options inherited from parent commands + +``` + -a, --address string Address to the UDM SSH server (default "192.168.1.1") + -d, --debug Show debug output + -p, --password string SSH password +``` + +### SEE ALSO + +* [udm-query](udm-query.md) - Tool to query Ubiquiti UniFi Dream Machines + diff --git a/docs/udm-query_dump.md b/docs/udm-query_dump.md new file mode 100644 index 0000000000000000000000000000000000000000..2bed4749c860fea7d8ddce5bdc192bcb483efc21 --- /dev/null +++ b/docs/udm-query_dump.md @@ -0,0 +1,30 @@ +## udm-query dump + +Export collection to JSON or a table + +``` +udm-query dump [flags] <database> <collection> [fields] +``` + +### Options + +``` + -h, --help help for dump + -o, --output string Write to file instead of stdout + -r, --render string Output rendering mode (default "table") + -s, --style string Table style (default "default") + -t, --table Output as table +``` + +### Options inherited from parent commands + +``` + -a, --address string Address to the UDM SSH server (default "192.168.1.1") + -d, --debug Show debug output + -p, --password string SSH password +``` + +### SEE ALSO + +* [udm-query](udm-query.md) - Tool to query Ubiquiti UniFi Dream Machines + diff --git a/docs/udm-query_list.md b/docs/udm-query_list.md new file mode 100644 index 0000000000000000000000000000000000000000..eb9c882d8b7e56cf39e45c42cfca54e3369df0bc --- /dev/null +++ b/docs/udm-query_list.md @@ -0,0 +1,27 @@ +## udm-query list + +List databases and their collections + +``` +udm-query list [flags] +``` + +### Options + +``` + -h, --help help for list + -s, --style string List style (default "default") +``` + +### Options inherited from parent commands + +``` + -a, --address string Address to the UDM SSH server (default "192.168.1.1") + -d, --debug Show debug output + -p, --password string SSH password +``` + +### SEE ALSO + +* [udm-query](udm-query.md) - Tool to query Ubiquiti UniFi Dream Machines + diff --git a/docs/udm-query_ping.md b/docs/udm-query_ping.md new file mode 100644 index 0000000000000000000000000000000000000000..dade5532d55117ec52ec581ae393cfb24644b807 --- /dev/null +++ b/docs/udm-query_ping.md @@ -0,0 +1,26 @@ +## udm-query ping + +Ping the database + +``` +udm-query ping [flags] +``` + +### Options + +``` + -h, --help help for ping +``` + +### Options inherited from parent commands + +``` + -a, --address string Address to the UDM SSH server (default "192.168.1.1") + -d, --debug Show debug output + -p, --password string SSH password +``` + +### SEE ALSO + +* [udm-query](udm-query.md) - Tool to query Ubiquiti UniFi Dream Machines + diff --git a/docs/udm-query_version.md b/docs/udm-query_version.md new file mode 100644 index 0000000000000000000000000000000000000000..eff70084d06afdac82f6e5cc31da1c251af0c9fb --- /dev/null +++ b/docs/udm-query_version.md @@ -0,0 +1,26 @@ +## udm-query version + +Display udm-query version + +``` +udm-query version [flags] +``` + +### Options + +``` + -h, --help help for version +``` + +### Options inherited from parent commands + +``` + -a, --address string Address to the UDM SSH server (default "192.168.1.1") + -d, --debug Show debug output + -p, --password string SSH password +``` + +### SEE ALSO + +* [udm-query](udm-query.md) - Tool to query Ubiquiti UniFi Dream Machines + diff --git a/go.mod b/go.mod index 3054e040394fb3fdb591bc2ec7053dcd12158c20..6e21448ffa70de252eeb2b46335baf749e8af52d 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,7 @@ require ( ) require ( + github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect github.com/fsnotify/fsnotify v1.5.1 // indirect github.com/go-stack/stack v1.8.0 // indirect github.com/golang/snappy v0.0.3 // indirect @@ -25,6 +26,7 @@ require ( github.com/pelletier/go-toml v1.9.4 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/rivo/uniseg v0.2.0 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/spf13/afero v1.6.0 // indirect github.com/spf13/cast v1.4.1 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect diff --git a/go.sum b/go.sum index 23b90511dd202c0987de713b9aa5ccbecbdea0f8..82767adff91190cd4f74e7851e5b007b5e0eb8e5 100644 --- a/go.sum +++ b/go.sum @@ -94,6 +94,7 @@ github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7 github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU= github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -357,6 +358,7 @@ github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6So github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/sagikazarmark/crypt v0.3.0/go.mod h1:uD/D+6UF4SrIR1uGEv7bBNkNqLGqUr43MRiaGWX1Nig=