Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style(bash-v2): out is not an array variable, do not refer to it as such #1681

Merged
merged 1 commit into from Apr 28, 2022

Conversation

scop
Copy link
Contributor

@scop scop commented Apr 27, 2022

Even though this to my surprise works, it doesn't accomplish anything but some confusion. Remove it.

Even though this to my surprise works, it doesn't accomplish anything
but some confusion. Remove it.
@github-actions github-actions bot added the size/S Denotes a PR that chanes 10-24 lines label Apr 27, 2022
@scop
Copy link
Contributor Author

scop commented Apr 27, 2022

Just something trivial to get out of the way for other likely improvements related to #1680.

Copy link
Collaborator

@marckhouzam marckhouzam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm... I'm not sure why I used out as an array variable. It might have started as an array in the early iterations of the script and then I didn't notice it wasn't one anymore.

But thanks @scop for cleaning that up.
I have tested with the cobra-completion-testing repo and with helm and it looks great.

@marckhouzam marckhouzam merged commit 4f0facb into spf13:master Apr 28, 2022
@marckhouzam marckhouzam added this to the 1.5.0 milestone Apr 28, 2022
@marckhouzam marckhouzam added the area/shell-completion All shell completions label Apr 28, 2022
@scop scop deleted the style/bash-v2-out branch April 28, 2022 05:23
@umarcor umarcor mentioned this pull request May 1, 2022
aviator-app bot pushed a commit to airplanedev/cli that referenced this pull request Jun 24, 2022
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [github.com/golang-jwt/jwt/v4](https://togithub.com/golang-jwt/jwt) | require | patch | `v4.4.1` -> `v4.4.2` |
| [github.com/spf13/cobra](https://togithub.com/spf13/cobra) | require | minor | `v1.4.0` -> `v1.5.0` |
| [github.com/stretchr/testify](https://togithub.com/stretchr/testify) | require | patch | `v1.7.2` -> `v1.7.5` |

---

### Release Notes

<details>
<summary>golang-jwt/jwt</summary>

### [`v4.4.2`](https://togithub.com/golang-jwt/jwt/releases/tag/v4.4.2)

[Compare Source](https://togithub.com/golang-jwt/jwt/compare/v4.4.1...v4.4.2)

#### What's Changed

-   Added MicahParks/keyfunc to extensions by [@&#8203;oxisto](https://togithub.com/oxisto) in [golang-jwt/jwt#194
-   Update link to v4 on pkg.go.dev page by [@&#8203;polRk](https://togithub.com/polRk) in [golang-jwt/jwt#195
-   add installation guidelines to the README file  by [@&#8203;morelmiles](https://togithub.com/morelmiles) in [golang-jwt/jwt#204
-   chore: replace ioutil with io and os by [@&#8203;estensen](https://togithub.com/estensen) in [golang-jwt/jwt#198
-   CI check for Go code formatting by [@&#8203;mfridman](https://togithub.com/mfridman) in [golang-jwt/jwt#206
-   Create SECURITY.md by [@&#8203;mfridman](https://togithub.com/mfridman) in [golang-jwt/jwt#171
-   Update SECURITY.md by [@&#8203;oxisto](https://togithub.com/oxisto) in [golang-jwt/jwt#207
-   Fixed integer overflow in NumericDate.MarshalJSON by [@&#8203;qqiao](https://togithub.com/qqiao) in [golang-jwt/jwt#200
-   Claims in rsa_test.go Table Driven Test are Unused by [@&#8203;gkech](https://togithub.com/gkech) in [golang-jwt/jwt#212

#### New Contributors

-   [@&#8203;polRk](https://togithub.com/polRk) made their first contribution in [golang-jwt/jwt#195
-   [@&#8203;morelmiles](https://togithub.com/morelmiles) made their first contribution in [golang-jwt/jwt#204
-   [@&#8203;estensen](https://togithub.com/estensen) made their first contribution in [golang-jwt/jwt#198
-   [@&#8203;qqiao](https://togithub.com/qqiao) made their first contribution in [golang-jwt/jwt#200
-   [@&#8203;gkech](https://togithub.com/gkech) made their first contribution in [golang-jwt/jwt#212

**Full Changelog**: golang-jwt/jwt@v4.4.1...v4.4.2

</details>

<details>
<summary>spf13/cobra</summary>

### [`v1.5.0`](https://togithub.com/spf13/cobra/releases/tag/v1.5.0)

[Compare Source](https://togithub.com/spf13/cobra/compare/v1.4.0...v1.5.0)

#### Spring 2022 Release 🌥️

Hello everyone! Welcome to another release of cobra. Completions continue to get better and better. This release adds a few really cool new features. We also continue to patch versions of our dependencies as they become available via dependabot. Happy coding!

#### Active help 👐🏼

Shout out to [@&#8203;marckhouzam](https://togithub.com/marckhouzam) for a big value add: Active Help [spf13/cobra#1482. With active help, a program can provide some inline warnings or hints for users as they hit tab. Now, your CLIs can be even more intuitive to use!

Currently active help is only supported for bash V2 and zsh. Marc wrote a whole guide on how to do this, so make sure to give it a good read to learn how you can add this to your cobra code! https://github.com/spf13/cobra/blob/master/active_help.md

#### Group flags 🧑🏼‍🤝‍🧑🏼

Cobra now has the ability to mark flags as required or exclusive as a ***group***. Shout out to our newest maintainer [@&#8203;johnSchnake](https://togithub.com/johnSchnake) for this! [spf13/cobra#1654 Let's say you have a `username` flag that ***MUST*** be partnered with a `password` flag. Well, now, you can enforce those as being required together:

```go
rootCmd.Flags().StringVarP(&u, "username", "u", "", "Username (required if password is set)")
rootCmd.Flags().StringVarP(&pw, "password", "p", "", "Password (required if username is set)")
rootCmd.MarkFlagsRequiredTogether("username", "password")
```

Flags may also be marked as "mutally exclusive" with the `MarkFlagsMutuallyExclusive(string, string ... )` command API. Refer to our [user guide documentation](https://togithub.com/spf13/cobra/blob/master/user_guide.md) for further info!

#### Completions 👀

-   Add backwards-compatibility tests for legacyArgs() by [@&#8203;marckhouzam](https://togithub.com/marckhouzam) in [spf13/cobra#1547
-   feat: Add how to load completions in your current zsh session by [@&#8203;ondrejsika](https://togithub.com/ondrejsika) in [spf13/cobra#1608
-   Introduce FixedCompletions by [@&#8203;emersion](https://togithub.com/emersion) in [spf13/cobra#1574
-   Add shell completion to flag groups by [@&#8203;marckhouzam](https://togithub.com/marckhouzam) in [spf13/cobra#1659
-   Modify brew prefix path in macOS system by [@&#8203;imxw](https://togithub.com/imxw) in [spf13/cobra#1719
-   perf(bash-v2): use backslash escape string expansion for tab by [@&#8203;scop](https://togithub.com/scop) in [spf13/cobra#1682
-   style(bash-v2): out is not an array variable, do not refer to it as such by [@&#8203;scop](https://togithub.com/scop) in [spf13/cobra#1681
-   perf(bash-v2): standard completion optimizations by [@&#8203;scop](https://togithub.com/scop) in [spf13/cobra#1683
-   style(bash): out is not an array variable, do not refer to it as such by [@&#8203;scop](https://togithub.com/scop) in [spf13/cobra#1684
-   perf(bash-v2): short-circuit descriptionless candidate lists by [@&#8203;scop](https://togithub.com/scop) in [spf13/cobra#1686
-   perf(bash-v2): speed up filtering entries with descriptions by [@&#8203;scop](https://togithub.com/scop) in [spf13/cobra#1689
-   perf(bash-v2): speed up filtering menu-complete descriptions by [@&#8203;scop](https://togithub.com/scop) in [spf13/cobra#1692
-   fix(bash-v2): skip empty completions when filtering descriptions by [@&#8203;scop](https://togithub.com/scop) in [spf13/cobra#1691
-   perf(bash-v2): read directly to COMPREPLY on descriptionless short circuit by [@&#8203;scop](https://togithub.com/scop) in [spf13/cobra#1700
-   fix: Don't complete \_command on zsh by [@&#8203;twpayne](https://togithub.com/twpayne) in [spf13/cobra#1690
-   Improve fish_completions code quality by [@&#8203;t29kida](https://togithub.com/t29kida) in [spf13/cobra#1515
-   Fix handling of descriptions for bash v3 by [@&#8203;marckhouzam](https://togithub.com/marckhouzam) in [spf13/cobra#1735
-   undefined or nil Args default to ArbitraryArgs by [@&#8203;umarcor](https://togithub.com/umarcor) in [spf13/cobra#1612
-   Add Command.SetContext by [@&#8203;joshcarp](https://togithub.com/joshcarp) in [spf13/cobra#1551
-   Wrap printf tab with quotes by [@&#8203;PapaCharlie](https://togithub.com/PapaCharlie) in [spf13/cobra#1665

#### Documentation 📝

-   Fixed typos in completions docs - [@&#8203;cuishuang](https://togithub.com/cuishuang) [spf13/cobra#1625
-   Removed `CHANGELOG.md` as it isn't updated - [@&#8203;johnSchnake](https://togithub.com/johnSchnake) [spf13/cobra#1634
-   Minor typo fix in `shell_completion.md` - [@&#8203;danieldn](https://togithub.com/danieldn) [spf13/cobra#1678
-   Changed branch name in the cobra generator link to 'main' - [@&#8203;skywalker2909](https://togithub.com/skywalker2909) [spf13/cobra#1645
-   Fix Command.Context comment by [@&#8203;katexochen](https://togithub.com/katexochen) in [spf13/cobra#1639
-   Change appropriate links from http:// to https:// where applicable - [@&#8203;deining](https://togithub.com/deining) [spf13/cobra#1695

#### Testing & CI ⚙️

-   Test on Golang 1.18 - [@&#8203;umarcor](https://togithub.com/umarcor) [spf13/cobra#1635
-   Use `RICHGO_FORCE_COLOR` - [@&#8203;umarcor](https://togithub.com/umarcor) [spf13/cobra#1647
-   Adds size labeler GitHub action by [@&#8203;jpmcb](https://togithub.com/jpmcb) in [spf13/cobra#1610
-   Update `stale-bot` settings - [@&#8203;jpmcb](https://togithub.com/jpmcb) [spf13/cobra#1609

#### Beep boop, bot commits 🤖

-   Bumped golangci/golangci-lint-action from 3.1.0 to 3.2.0 - [@&#8203;dependabot](https://togithub.com/dependabot) [spf13/cobra#1697
-   Bump codelytv/pr-size-labeler from 1.8.0 to 1.8.1 - [@&#8203;dependabot](https://togithub.com/dependabot) [spf13/cobra#1661
-   Bump actions/stale from 1 to 5 by [@&#8203;dependabot](https://togithub.com/dependabot) in [spf13/cobra#1618
-   Bump actions/cache from 2 to 3 by [@&#8203;dependabot](https://togithub.com/dependabot) in [spf13/cobra#1640
-   Bump actions/labeler from 3 to 4 by [@&#8203;dependabot](https://togithub.com/dependabot) in [spf13/cobra#1620
-   Bump golangci/golangci-lint-action from 2 to 3.1.0 by [@&#8203;dependabot](https://togithub.com/dependabot) in [spf13/cobra#1615
-   Bump actions/checkout from 2 to 3 by [@&#8203;dependabot](https://togithub.com/dependabot) in [spf13/cobra#1619
-   Bump github.com/cpuguy83/go-md2man/v2 from 2.0.1 to 2.0.2 by [@&#8203;dependabot](https://togithub.com/dependabot) in [spf13/cobra#1688
-   Bump actions/setup-go from 2 to 3 by [@&#8203;dependabot](https://togithub.com/dependabot) in [spf13/cobra#1660

#### Misc 💭

-   Use `errors.Is()` to check for errors - [@&#8203;Luap99](https://togithub.com/Luap99) [spf13/cobra#1730
-   Prefer ReplaceAll instead of Replace(..., -1) by [@&#8203;WhyNotHugo](https://togithub.com/WhyNotHugo) in [spf13/cobra#1530
-   Add Kubescape to projects - [@&#8203;avinashupadhya99](https://togithub.com/avinashupadhya99) [spf13/cobra#1642
-   Add Pulumi as a project using cobra by [@&#8203;iwahbe](https://togithub.com/iwahbe) in [spf13/cobra#1720
-   Add Polygon Edge as a project using Cobra by [@&#8203;zivkovicmilos](https://togithub.com/zivkovicmilos) in [spf13/cobra#1672

Shoutout to *ALL* our contributors (and all the new first time contributors!!) - great work everyone!! Cobra and it's huge impact wouldn't be possible without you 👏🏼  🚀  🐍

**Full Changelog**: spf13/cobra@v1.4.0...v1.5.0

</details>

<details>
<summary>stretchr/testify</summary>

### [`v1.7.5`](https://togithub.com/stretchr/testify/compare/v1.7.4...v1.7.5)

[Compare Source](https://togithub.com/stretchr/testify/compare/v1.7.4...v1.7.5)

### [`v1.7.4`](https://togithub.com/stretchr/testify/compare/v1.7.3...v1.7.4)

[Compare Source](https://togithub.com/stretchr/testify/compare/v1.7.3...v1.7.4)

### [`v1.7.3`](https://togithub.com/stretchr/testify/compare/v1.7.2...v1.7.3)

[Compare Source](https://togithub.com/stretchr/testify/compare/v1.7.2...v1.7.3)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "before 5am on Thursday" in timezone America/New_York, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://togithub.com/renovatebot/renovate/discussions) if that's undesired.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.
gcf-merge-on-green bot pushed a commit to renovate-bot/gapic-showcase that referenced this pull request Jun 27, 2022
…is#1128)

[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [github.com/spf13/cobra](https://togithub.com/spf13/cobra) | require | minor | `v1.4.0` -> `v1.5.0` |

---

### Release Notes

<details>
<summary>spf13/cobra</summary>

### [`v1.5.0`](https://togithub.com/spf13/cobra/releases/tag/v1.5.0)

[Compare Source](https://togithub.com/spf13/cobra/compare/v1.4.0...v1.5.0)

#### Spring 2022 Release 🌥️

Hello everyone! Welcome to another release of cobra. Completions continue to get better and better. This release adds a few really cool new features. We also continue to patch versions of our dependencies as they become available via dependabot. Happy coding!

#### Active help 👐🏼

Shout out to [@&#8203;marckhouzam](https://togithub.com/marckhouzam) for a big value add: Active Help [spf13/cobra#1482. With active help, a program can provide some inline warnings or hints for users as they hit tab. Now, your CLIs can be even more intuitive to use!

Currently active help is only supported for bash V2 and zsh. Marc wrote a whole guide on how to do this, so make sure to give it a good read to learn how you can add this to your cobra code! https://github.com/spf13/cobra/blob/master/active_help.md

#### Group flags 🧑🏼‍🤝‍🧑🏼

Cobra now has the ability to mark flags as required or exclusive as a ***group***. Shout out to our newest maintainer [@&#8203;johnSchnake](https://togithub.com/johnSchnake) for this! [spf13/cobra#1654 Let's say you have a `username` flag that ***MUST*** be partnered with a `password` flag. Well, now, you can enforce those as being required together:

```go
rootCmd.Flags().StringVarP(&u, "username", "u", "", "Username (required if password is set)")
rootCmd.Flags().StringVarP(&pw, "password", "p", "", "Password (required if username is set)")
rootCmd.MarkFlagsRequiredTogether("username", "password")
```

Flags may also be marked as "mutally exclusive" with the `MarkFlagsMutuallyExclusive(string, string ... )` command API. Refer to our [user guide documentation](https://togithub.com/spf13/cobra/blob/master/user_guide.md) for further info!

#### Completions 👀

-   Add backwards-compatibility tests for legacyArgs() by [@&#8203;marckhouzam](https://togithub.com/marckhouzam) in [spf13/cobra#1547
-   feat: Add how to load completions in your current zsh session by [@&#8203;ondrejsika](https://togithub.com/ondrejsika) in [spf13/cobra#1608
-   Introduce FixedCompletions by [@&#8203;emersion](https://togithub.com/emersion) in [spf13/cobra#1574
-   Add shell completion to flag groups by [@&#8203;marckhouzam](https://togithub.com/marckhouzam) in [spf13/cobra#1659
-   Modify brew prefix path in macOS system by [@&#8203;imxw](https://togithub.com/imxw) in [spf13/cobra#1719
-   perf(bash-v2): use backslash escape string expansion for tab by [@&#8203;scop](https://togithub.com/scop) in [spf13/cobra#1682
-   style(bash-v2): out is not an array variable, do not refer to it as such by [@&#8203;scop](https://togithub.com/scop) in [spf13/cobra#1681
-   perf(bash-v2): standard completion optimizations by [@&#8203;scop](https://togithub.com/scop) in [spf13/cobra#1683
-   style(bash): out is not an array variable, do not refer to it as such by [@&#8203;scop](https://togithub.com/scop) in [spf13/cobra#1684
-   perf(bash-v2): short-circuit descriptionless candidate lists by [@&#8203;scop](https://togithub.com/scop) in [spf13/cobra#1686
-   perf(bash-v2): speed up filtering entries with descriptions by [@&#8203;scop](https://togithub.com/scop) in [spf13/cobra#1689
-   perf(bash-v2): speed up filtering menu-complete descriptions by [@&#8203;scop](https://togithub.com/scop) in [spf13/cobra#1692
-   fix(bash-v2): skip empty completions when filtering descriptions by [@&#8203;scop](https://togithub.com/scop) in [spf13/cobra#1691
-   perf(bash-v2): read directly to COMPREPLY on descriptionless short circuit by [@&#8203;scop](https://togithub.com/scop) in [spf13/cobra#1700
-   fix: Don't complete \_command on zsh by [@&#8203;twpayne](https://togithub.com/twpayne) in [spf13/cobra#1690
-   Improve fish_completions code quality by [@&#8203;t29kida](https://togithub.com/t29kida) in [spf13/cobra#1515
-   Fix handling of descriptions for bash v3 by [@&#8203;marckhouzam](https://togithub.com/marckhouzam) in [spf13/cobra#1735
-   undefined or nil Args default to ArbitraryArgs by [@&#8203;umarcor](https://togithub.com/umarcor) in [spf13/cobra#1612
-   Add Command.SetContext by [@&#8203;joshcarp](https://togithub.com/joshcarp) in [spf13/cobra#1551
-   Wrap printf tab with quotes by [@&#8203;PapaCharlie](https://togithub.com/PapaCharlie) in [spf13/cobra#1665

#### Documentation 📝

-   Fixed typos in completions docs - [@&#8203;cuishuang](https://togithub.com/cuishuang) [spf13/cobra#1625
-   Removed `CHANGELOG.md` as it isn't updated - [@&#8203;johnSchnake](https://togithub.com/johnSchnake) [spf13/cobra#1634
-   Minor typo fix in `shell_completion.md` - [@&#8203;danieldn](https://togithub.com/danieldn) [spf13/cobra#1678
-   Changed branch name in the cobra generator link to 'main' - [@&#8203;skywalker2909](https://togithub.com/skywalker2909) [spf13/cobra#1645
-   Fix Command.Context comment by [@&#8203;katexochen](https://togithub.com/katexochen) in [spf13/cobra#1639
-   Change appropriate links from http:// to https:// where applicable - [@&#8203;deining](https://togithub.com/deining) [spf13/cobra#1695

#### Testing & CI ⚙️

-   Test on Golang 1.18 - [@&#8203;umarcor](https://togithub.com/umarcor) [spf13/cobra#1635
-   Use `RICHGO_FORCE_COLOR` - [@&#8203;umarcor](https://togithub.com/umarcor) [spf13/cobra#1647
-   Adds size labeler GitHub action by [@&#8203;jpmcb](https://togithub.com/jpmcb) in [spf13/cobra#1610
-   Update `stale-bot` settings - [@&#8203;jpmcb](https://togithub.com/jpmcb) [spf13/cobra#1609

#### Beep boop, bot commits 🤖

-   Bumped golangci/golangci-lint-action from 3.1.0 to 3.2.0 - [@&#8203;dependabot](https://togithub.com/dependabot) [spf13/cobra#1697
-   Bump codelytv/pr-size-labeler from 1.8.0 to 1.8.1 - [@&#8203;dependabot](https://togithub.com/dependabot) [spf13/cobra#1661
-   Bump actions/stale from 1 to 5 by [@&#8203;dependabot](https://togithub.com/dependabot) in [spf13/cobra#1618
-   Bump actions/cache from 2 to 3 by [@&#8203;dependabot](https://togithub.com/dependabot) in [spf13/cobra#1640
-   Bump actions/labeler from 3 to 4 by [@&#8203;dependabot](https://togithub.com/dependabot) in [spf13/cobra#1620
-   Bump golangci/golangci-lint-action from 2 to 3.1.0 by [@&#8203;dependabot](https://togithub.com/dependabot) in [spf13/cobra#1615
-   Bump actions/checkout from 2 to 3 by [@&#8203;dependabot](https://togithub.com/dependabot) in [spf13/cobra#1619
-   Bump github.com/cpuguy83/go-md2man/v2 from 2.0.1 to 2.0.2 by [@&#8203;dependabot](https://togithub.com/dependabot) in [spf13/cobra#1688
-   Bump actions/setup-go from 2 to 3 by [@&#8203;dependabot](https://togithub.com/dependabot) in [spf13/cobra#1660

#### Misc 💭

-   Use `errors.Is()` to check for errors - [@&#8203;Luap99](https://togithub.com/Luap99) [spf13/cobra#1730
-   Prefer ReplaceAll instead of Replace(..., -1) by [@&#8203;WhyNotHugo](https://togithub.com/WhyNotHugo) in [spf13/cobra#1530
-   Add Kubescape to projects - [@&#8203;avinashupadhya99](https://togithub.com/avinashupadhya99) [spf13/cobra#1642
-   Add Pulumi as a project using cobra by [@&#8203;iwahbe](https://togithub.com/iwahbe) in [spf13/cobra#1720
-   Add Polygon Edge as a project using Cobra by [@&#8203;zivkovicmilos](https://togithub.com/zivkovicmilos) in [spf13/cobra#1672

Shoutout to *ALL* our contributors (and all the new first time contributors!!) - great work everyone!! Cobra and it's huge impact wouldn't be possible without you 👏🏼  🚀  🐍

**Full Changelog**: spf13/cobra@v1.4.0...v1.5.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/gapic-showcase).
hoshsadiq pushed a commit to zulucmd/zulu that referenced this pull request Dec 31, 2022
style(bash-v2): out is not an array variable, do not refer to it as such

Even though this to my surprise works, it doesn't accomplish anything but some confusion. Remove it.

Merge spf13/cobra#1681

---

perf(bash-v2): use backslash escape string expansion for tab

Using a command substitution, i.e. a subshell, with `printf` is expensive for this purpose. For example `__*_format_comp_descriptions` is run once for each completion candidate; the expense adds up and shows when there are a lot of them.

This shaves off roughly 25% of the times I receive for my test case in #1680 (~2 seconds before, ~1.5 after).

Merge spf13/cobra#1682

---

perf(bash-v2): standard completion optimizations

Refactor to remove two loops over the entire list of candidates.

Format descriptions only for completions that are actually going to be displayed, instead of for all candidates.

Format descriptions inline in completions array, removing need for a command substitution/subshell and a printf escape per displayed completion.

These changes shave off a second or so from my case at hand in #1680, it was roughly ~1.7s before, is now ~0.7s after.
The diff is largish, but the bulk of it is in `__%[1]s_format_comp_descriptions` due to indentation changes, there aren't that many lines actually changed in it either. `git show -w` helps with the review.

Caveat: I have not actually tested generating completions with this code. I worked on the improvements by tweaking an existing emitted completion shell file, then manually ported the changes to the template in Go code here. Hopefully I didn't introduce bugs while doing that. (The code compiles, and test suite fails just like it did before this change, no regressions noticed.)

Merge spf13/cobra#1683

---

perf(bash-v2): short-circuit descriptionless candidate lists

If the list of candidates has no descriptions, short circuit all the description processing logic, basically just do a `compgen -W` for the whole list and be done with it.

We could conceivably do some optimizations like this and more when generating the completions with `--no-descriptions` in Go code, by omitting some parts we know won't be needed, or doing some things differently. But doing it this way in bash, the improvements are available also to completions generated with descriptions enabled when they are invoked for completion cases that produce no descriptions. The result after this for descriptionless entries seems fast enough so it seems there's no immediate need to look into doing that.

This alone pretty much eliminates all the slowness related to my specific use case in #1680, bringing it down to ~0.07s (yes, there _is_ a zero on the right of the period), so for the time being I'm not inclined to look into further optimizations at least for the code path where there are no descriptions. Related to #1683, but I suggest merging both as they affect different scenarios.

Same caveat as in #1683 about testing and the way the change was made applies here.

Merge spf13/cobra#1686

---

perf(bash-v2): speed up filtering entries with descriptions

Use simple prefix match instead of single word `compgen -W` command substitution for each candidate match.

It's a bit late, but I can't think of a case where this replacement wouldn't be ok this late at night. Performancewise this improves the cases with descriptions quite a bit, with current marckhouzam/cobra-completion-testing#15 on my box, the v2 numbers look like the following (I've stripped the v1 numbers from each list below).

Before (current master, #1686 not merged yet):
```
Processing 1000 completions took 0.492 seconds which is less than the 1.0 seconds limit
Processing 1000 completions took 0.600 seconds which is less than the 2.0 seconds limit
Processing 1000 completions took 0.455 seconds which is less than the 1.0 seconds limit
Processing 1000 completions took 0.578 seconds which is less than the 2.0 seconds limit
Processing 1000 completions took 0.424 seconds which is less than the 1.0 seconds limit
Processing 1000 completions took 0.570 seconds which is less than the 2.0 seconds limit
Processing 1000 completions took 0.502 seconds which is less than the 1.0 seconds limit
Processing 1000 completions took 0.585 seconds which is less than the 2.0 seconds limit
```
After (also without #1686):
```
Processing 1000 completions took 0.070 seconds which is less than the 1.0 seconds limit
Processing 1000 completions took 0.165 seconds which is less than the 2.0 seconds limit
Processing 1000 completions took 0.072 seconds which is less than the 1.0 seconds limit
Processing 1000 completions took 0.181 seconds which is less than the 2.0 seconds limit
Processing 1000 completions took 0.089 seconds which is less than the 1.0 seconds limit
Processing 1000 completions took 0.254 seconds which is less than the 2.0 seconds limit
Processing 1000 completions took 0.058 seconds which is less than the 1.0 seconds limit
Processing 1000 completions took 0.122 seconds which is less than the 2.0 seconds limit
```

For curiosity, even though this improves the descriptionless case quite a bit too, #1686 is still relevant, with it applied on top of this one:
```
Processing 1000 completions took 0.036 seconds which is less than the 1.0 seconds limit
Processing 1000 completions took 0.165 seconds which is less than the 2.0 seconds limit
Processing 1000 completions took 0.047 seconds which is less than the 1.0 seconds limit
Processing 1000 completions took 0.183 seconds which is less than the 2.0 seconds limit
Processing 1000 completions took 0.051 seconds which is less than the 1.0 seconds limit
Processing 1000 completions took 0.264 seconds which is less than the 2.0 seconds limit
Processing 1000 completions took 0.036 seconds which is less than the 1.0 seconds limit
Processing 1000 completions took 0.122 seconds which is less than the 2.0 seconds limit
```

Merge spf13/cobra#1689

---

fix(bash-v2): skip empty completions when filtering descriptions

`read` gives a last null value following a trailing newline.

Regression from fb8031162c2ffab270774f13c6904bb04cbba5a7.

We could drop the `\n` from the feeding `printf` to accomplish the same end result, but I'm planning to submit some related cleanups a bit later that wouldn't play well with that approach, so I went with explicit filtering here.

Merge spf13/cobra#1691

---

perf(bash-v2): speed up filtering menu-complete descriptions

Similarly as fb8031162c2ffab270774f13c6904bb04cbba5a7 (+ the empty entry fix in spf13/cobra#1691) did for the "regular", non-menu completion cases.

I have no numbers on this, but I'm assuming the speedups seen elsewhere are here too, and didn't notice anything breaking in casual manual tests.

Could be useful to add some perf numbers for the menu-complete code path too to [marckhouzam/cobra-completion-testing](https://github.com/marckhouzam/cobra-completion-testing/) (maybe as well as other tests, haven't checked if there are any).

Merge spf13/cobra#1692

---

perf(bash-v2): read directly to COMPREPLY on descriptionless short circuit

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.

Before:
```
...
<= TIMING => no descriptions: 1000 completions took 0.039 seconds < 0.2 seconds limit
...
<= TIMING => no descriptions: 1000 completions took 0.046 seconds < 0.2 seconds limit
...
```

After:
```
...
<= TIMING => no descriptions: 1000 completions took 0.022 seconds < 0.2 seconds limit
...
<= TIMING => no descriptions: 1000 completions took 0.024 seconds < 0.2 seconds limit
...
```

Merge spf13/cobra#1700
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/shell-completion All shell completions size/S Denotes a PR that chanes 10-24 lines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants