From e1ded5cd9480aa9921a8cb0f646b6b569ac1b9d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Tue, 17 May 2022 20:47:47 +0300 Subject: [PATCH 1/3] fix(bash-v2): skip empty completions when filtering descriptions (#1691) `read` gives a last null value following a trailing newline. Regression from fb8031162c2ffab270774f13c6904bb04cbba5a7. --- bash_completionsV2.go | 1 + 1 file changed, 1 insertion(+) diff --git a/bash_completionsV2.go b/bash_completionsV2.go index 5e558a51..97202f1b 100644 --- a/bash_completionsV2.go +++ b/bash_completionsV2.go @@ -188,6 +188,7 @@ __%[1]s_handle_standard_completion_case() { local compline # Look for the longest completion so that we can format things nicely while IFS='' read -r compline; do + [[ -z $compline ]] && continue # Strip any description before checking the length comp=${compline%%%%$tab*} # Only consider the completions that match From ffa8860dbe017851bc4e8ff4fb2b6249cfc1e4d8 Mon Sep 17 00:00:00 2001 From: Andreas Deininger Date: Tue, 17 May 2022 20:28:13 +0200 Subject: [PATCH 2/3] Change links from http:// to https:// (#1695) --- README.md | 4 ++-- doc/md_docs.md | 2 +- doc/rest_docs.md | 2 +- doc/yaml_docs.md | 2 +- projects_using_cobra.md | 10 +++++----- user_guide.md | 6 +++--- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 55dc39d0..2bf15208 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Cobra is a library for creating powerful modern CLI applications. -Cobra is used in many Go projects such as [Kubernetes](http://kubernetes.io/), +Cobra is used in many Go projects such as [Kubernetes](https://kubernetes.io/), [Hugo](https://gohugo.io), and [Github CLI](https://github.com/cli/cli) to name a few. [This list](./projects_using_cobra.md) contains a more extensive list of projects using Cobra. @@ -28,7 +28,7 @@ Cobra provides: * Automatically generated man pages for your application * Command aliases so you can change things without breaking them * The flexibility to define your own help, usage, etc. -* Optional seamless integration with [viper](http://github.com/spf13/viper) for 12-factor apps +* Optional seamless integration with [viper](https://github.com/spf13/viper) for 12-factor apps # Concepts diff --git a/doc/md_docs.md b/doc/md_docs.md index 5c870625..1659175c 100644 --- a/doc/md_docs.md +++ b/doc/md_docs.md @@ -85,7 +85,7 @@ func GenMarkdownCustom(cmd *Command, out *bytes.Buffer, linkHandler func(string) } ``` -The `filePrepender` will prepend the return value given the full filepath to the rendered Markdown file. A common use case is to add front matter to use the generated documentation with [Hugo](http://gohugo.io/): +The `filePrepender` will prepend the return value given the full filepath to the rendered Markdown file. A common use case is to add front matter to use the generated documentation with [Hugo](https://gohugo.io/): ```go const fmTemplate = `--- diff --git a/doc/rest_docs.md b/doc/rest_docs.md index 6098430e..3041c573 100644 --- a/doc/rest_docs.md +++ b/doc/rest_docs.md @@ -85,7 +85,7 @@ func GenReSTCustom(cmd *Command, out *bytes.Buffer, linkHandler func(string, str } ``` -The `filePrepender` will prepend the return value given the full filepath to the rendered ReST file. A common use case is to add front matter to use the generated documentation with [Hugo](http://gohugo.io/): +The `filePrepender` will prepend the return value given the full filepath to the rendered ReST file. A common use case is to add front matter to use the generated documentation with [Hugo](https://gohugo.io/): ```go const fmTemplate = `--- diff --git a/doc/yaml_docs.md b/doc/yaml_docs.md index 1a9b7c6a..172e61d1 100644 --- a/doc/yaml_docs.md +++ b/doc/yaml_docs.md @@ -82,7 +82,7 @@ func GenYamlCustom(cmd *Command, out *bytes.Buffer, linkHandler func(string) str } ``` -The `filePrepender` will prepend the return value given the full filepath to the rendered Yaml file. A common use case is to add front matter to use the generated documentation with [Hugo](http://gohugo.io/): +The `filePrepender` will prepend the return value given the full filepath to the rendered Yaml file. A common use case is to add front matter to use the generated documentation with [Hugo](https://gohugo.io/): ```go const fmTemplate = `--- diff --git a/projects_using_cobra.md b/projects_using_cobra.md index 1d2266dc..4ac87d3c 100644 --- a/projects_using_cobra.md +++ b/projects_using_cobra.md @@ -1,8 +1,8 @@ ## Projects using Cobra - [Arduino CLI](https://github.com/arduino/arduino-cli) -- [Bleve](http://www.blevesearch.com/) -- [CockroachDB](http://www.cockroachlabs.com/) +- [Bleve](https://blevesearch.com/) +- [CockroachDB](https://www.cockroachlabs.com/) - [Cosmos SDK](https://github.com/cosmos/cosmos-sdk) - [Datree](https://github.com/datreeio/datree) - [Delve](https://github.com/derekparker/delve) @@ -14,14 +14,14 @@ - [Github CLI](https://github.com/cli/cli) - [GitHub Labeler](https://github.com/erdaltsksn/gh-label) - [Golangci-lint](https://golangci-lint.run) -- [GopherJS](http://www.gopherjs.org/) +- [GopherJS](https://github.com/gopherjs/gopherjs) - [GoReleaser](https://goreleaser.com) - [Helm](https://helm.sh) - [Hugo](https://gohugo.io) - [Infracost](https://github.com/infracost/infracost) - [Istio](https://istio.io) - [Kool](https://github.com/kool-dev/kool) -- [Kubernetes](http://kubernetes.io/) +- [Kubernetes](https://kubernetes.io/) - [Kubescape](https://github.com/armosec/kubescape) - [Linkerd](https://linkerd.io/) - [Mattermost-server](https://github.com/mattermost/mattermost-server) @@ -39,7 +39,7 @@ - [Pixie](https://github.com/pixie-io/pixie) - [Polygon Edge](https://github.com/0xPolygon/polygon-edge) - [Pouch](https://github.com/alibaba/pouch) -- [ProjectAtomic (enterprise)](http://www.projectatomic.io/) +- [ProjectAtomic (enterprise)](https://www.projectatomic.io/) - [Prototool](https://github.com/uber/prototool) - [QRcp](https://github.com/claudiodangelis/qrcp) - [Random](https://github.com/erdaltsksn/random) diff --git a/user_guide.md b/user_guide.md index 56a1e9c6..cde4032b 100644 --- a/user_guide.md +++ b/user_guide.md @@ -51,7 +51,7 @@ var rootCmd = &cobra.Command{ Short: "Hugo is a very fast static site generator", Long: `A Fast and Flexible Static Site Generator built with love by spf13 and friends in Go. - Complete documentation is available at http://hugo.spf13.com`, + Complete documentation is available at https://gohugo.io/documentation/`, Run: func(cmd *cobra.Command, args []string) { // Do Stuff Here }, @@ -429,7 +429,7 @@ a count and a string.`, } ``` -For a more complete example of a larger application, please checkout [Hugo](http://gohugo.io/). +For a more complete example of a larger application, please checkout [Hugo](https://gohugo.io/). ## Help Command @@ -627,7 +627,7 @@ Did you mean this? Run 'hugo --help' for usage. ``` -Suggestions are automatic based on every subcommand registered and use an implementation of [Levenshtein distance](http://en.wikipedia.org/wiki/Levenshtein_distance). Every registered command that matches a minimum distance of 2 (ignoring case) will be displayed as a suggestion. +Suggestions are automatic based on every subcommand registered and use an implementation of [Levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance). Every registered command that matches a minimum distance of 2 (ignoring case) will be displayed as a suggestion. If you need to disable suggestions or tweak the string distance in your command, use: From 5b11656e45a6a6579298a3b28c71f456ff196ad6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Wed, 18 May 2022 03:57:08 +0300 Subject: [PATCH 3/3] perf(bash-v2): read directly to COMPREPLY on descriptionless short circuit (#1700) Not that it'd really matter that much performancewise given the level we are at for this case, but this change makes the short circuit roughly twice as fast on my box as it was for the 1000 rounds done in marckhouzam/cobra-completion-testing. Perhaps more importantly, this makes the code arguably slightly cleaner. --- bash_completionsV2.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bash_completionsV2.go b/bash_completionsV2.go index 97202f1b..e61e27c9 100644 --- a/bash_completionsV2.go +++ b/bash_completionsV2.go @@ -178,9 +178,7 @@ __%[1]s_handle_standard_completion_case() { # Short circuit to optimize if we don't have descriptions if [[ $out != *$tab* ]]; then - while IFS='' read -r comp; do - COMPREPLY+=("$comp") - done < <(IFS=$'\n' compgen -W "$out" -- "$cur") + IFS=$'\n' read -ra COMPREPLY -d '' < <(IFS=$'\n' compgen -W "$out" -- "$cur") return 0 fi