Commit graph

889 commits

Author SHA1 Message Date
Paul Meyer 3a1795bc25
Fix Command.Context comment (#1639) 2022-03-21 13:35:35 -04:00
Joshua Carpeggiani f848943afd
Add Command.SetContext (#1551)
Increases flexibility in how Contexts can be used with Cobra.
2022-03-18 06:01:58 -04:00
Simon Ser 5d066b77b5
Introduce FixedCompletions (#1574)
Example usage:

    choices := []string{"choice1", "choice2", "choice3"}
    cmd.RegisterFlagCompletionFunc(cobra.FixedCompletions(choices, ShellCompDirectiveNoFileComp))
2022-03-17 21:37:54 -04:00
Marc Khouzam 94e552d8d6
Add backwards-compatibility tests for legacyArgs() (#1547)
These tests make sure we don't break backwards-compatibility with
respect to the current behaviour of legacyArgs().

See #1500 for the back-story.

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
2022-03-17 21:36:47 -04:00
Ondrej Sika 8cc7be2119
feat: Add how to load completions in your current zsh session (#1608) 2022-03-17 17:55:16 -04:00
Unai Martinez-Corral 65b1195d6e
ci: test on Golang 1.18 (#1635) 2022-03-17 06:26:10 -04:00
John Schnake 37463cff2c
Remove CHANGELOG.md as it isn't updated (#1634)
Fixes #1442

Signed-off-by: John Schnake <jschnake@vmware.com>
2022-03-16 09:34:01 -06:00
cui fliter 81d27c8f8d
fix some typos (#1625)
* fix some typos

Signed-off-by: cuishuang <imcusg@gmail.com>
2022-03-14 07:05:53 -04:00
John McBride 5b2b9e9f61
Removes viper dependency by removing cobra/ CLI tool (#1604)
The cobra bootstrapping CLI tool has moved to
https://github.com/spf13/cobra-cli

Signed-off-by: John McBride <jmcbride@vmware.com>
2022-03-10 08:19:35 -07:00
umarcor 9369465955 labeler: fix syntax 2022-03-09 12:34:54 -05:00
John McBride e1b831e5c2
Updates labeler for new labels (#1613)
Signed-off-by: John McBride <jmcbride@vmware.com>
2022-03-08 17:10:09 -07:00
Marc Khouzam 8267283cfe
Add MAINTAINERS file (alphabetical order) (#1545)
This should help the community know who they can turn to, but also
give credit to the maintainers for all their hard work.

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
2022-02-28 08:24:45 -07:00
Hannah Troisi 6d2dc43606
Add Pixie to projects. (#1581) 2022-02-24 14:51:17 -05:00
Shyim a599632379
Fix install command (#1576) 2022-02-17 10:17:44 -07:00
Marian Steinbach 7cabfeb8f8
Update Go Doc link and badge (#1593)
Use `pkg.go.dev` instead of `godoc.org`
2022-02-16 15:17:17 -07:00
J.R. Hill e04ec72550
Bump license year to 2022 in golden files (#1575) 2022-01-06 13:58:09 -07:00
dependabot[bot] cb9d7b1cec
Bump github.com/spf13/viper from 1.10.0 to 1.10.1 (#1567)
Bumps [github.com/spf13/viper](https://github.com/spf13/viper) from 1.10.0 to 1.10.1.
- [Release notes](https://github.com/spf13/viper/releases)
- [Commits](https://github.com/spf13/viper/compare/v1.10.0...v1.10.1)

---
updated-dependencies:
- dependency-name: github.com/spf13/viper
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Note: For historical context on this viper dependency bump, please refer to https://github.com/spf13/cobra/pull/1539

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: John McBride <jmcbride@vmware.com>
2021-12-20 21:00:40 -07:00
dependabot[bot] 178edbb247
Bump github.com/spf13/viper from 1.9.0 to 1.10.0 (#1561)
Bumps [github.com/spf13/viper](https://github.com/spf13/viper) from 1.9.0 to 1.10.0.
- [Release notes](https://github.com/spf13/viper/releases)
- [Commits](https://github.com/spf13/viper/compare/v1.9.0...v1.10.0)

---
updated-dependencies:
- dependency-name: github.com/spf13/viper
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-12-14 11:22:51 -07:00
Marc Khouzam 9054739e08
Remove __complete cmd for program without subcmds (#1563)
Fixes #1562

Programs that don't have sub-commands can accept any number of args.
However, when doing shell completion for such programs, within the
__complete code this very __complete command makes it that the program
suddenly has a sub-command, and the call to Find() -> legacyArgs() will
then return an error if there are more than one argument on the
command-line being completed.

To avoid this, we first remove the __complete command in such a case so
as to get back to having no sub-commands.

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
2021-12-14 11:22:22 -07:00
John McBride 19c9c74384
Always include the os package import when generating the root command (#1557)
Signed-off-by: John McBride <jmcbride@vmware.com>
2021-12-09 14:47:27 -07:00
dependabot[bot] 01e05b8ea1
Bump github.com/spf13/viper from 1.8.1 to 1.9.0 (#1554)
Bumps [github.com/spf13/viper](https://github.com/spf13/viper) from 1.8.1 to 1.9.0.
- [Release notes](https://github.com/spf13/viper/releases)
- [Commits](https://github.com/spf13/viper/compare/v1.8.1...v1.9.0)

---
updated-dependencies:
- dependency-name: github.com/spf13/viper
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-12-08 11:56:37 -07:00
Unai Martinez-Corral 36bff0a4d5
fix root.go.golden (#1552) 2021-12-07 16:24:06 -07:00
Stefan Weil 1854bb5c96
Fix some typos (mostly found by codespell) (#1514)
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2021-12-07 16:06:52 -07:00
Matthieu MOREL ff2c55e323
chore(ci): use golangci-lint-action (#1477)
Signed-off-by: Matthieu MOREL <mmorel-35@users.noreply.github.com>
2021-12-07 16:06:09 -07:00
ANGkeith 1beb476da9
fix: Duplicate error message from cobra init boilerplates (#1463) 2021-12-07 16:03:24 -07:00
Marc Khouzam 6f84ef4875
Provide option to hide default 'completion' cmd (#1541)
Fixes #1507

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
2021-12-07 16:02:02 -07:00
meyermarcel ee75a2b1ed
Remove trailing spaces from bash completion command description (#1520) 2021-12-07 16:01:22 -07:00
darklore 25bab5a398
Fix invalid shell completion when used with ~/.cobra.yaml (#1510)
`cobra completion` outputs invalid output "Using config file:" at the
top of the completion script. when ~/.cobra.yaml exists.
2021-12-07 16:00:50 -07:00
Marc Khouzam 3fed3ef5ad
Support different bash completion options (#1509)
https://github.com/spf13/cobra/issues/1508

Based on the documentation found here
https://www.gnu.org/software/bash/manual/html_node/Commands-For-Completion.html
we remove descriptions for the following completion types:
- menu-complete
- menu-complete-backward
- insert-completions

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
2021-12-07 15:59:41 -07:00
Sebastiaan van Stijn 507caf5ac8
completions: fix mixed tab/spaces indentation (#1473)
These templates use 4 spaces for indentation, but some lines
used tabs.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-12-07 15:57:57 -07:00
favonia c7a4421715
fix: typo in {bash,zsh}_completions.go (#1459)
* Fix typo in bash_completions.go
* Fix the same typo in zsh_completions.go
2021-12-07 15:53:38 -07:00
Frank Chiarulli Jr c3573e220c
Completion: Capitalize short desc, and remove extra space from long (#1455) 2021-12-07 15:52:50 -07:00
Carlos Alexandro Becker dd40ab071f
feat: improve completions help formatting (#1444)
Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
2021-12-07 15:51:48 -07:00
Ron Green d298d79e6a
Update shell_completions.md to have automatically rootcmd (#1372)
* Update shell_completions.md
2021-12-07 15:46:48 -07:00
Eden Tsai 6f19fa9f61
fix: unbound variables in bash completion (#1321)
when `set -o nounset` in Bash,
the warnings of unbound variables will break the bash completion.

use `kubectl` as example:

```sh
$ set -o nounset
$ my-cli <Tab>-bash: BASH_COMP_DEBUG_FILE: unbound variable
$
```

the warning break bash completion without any completion result,
and cause my cursor move to the newline.

Use `${variable:-}` substitution in Bash,
that assign an empty string as default for unbound variables to fix the warnings.
2021-12-07 15:44:39 -07:00
Unai Martinez-Corral d65ba125a3
github: add dependabot configuration file (#1427)
Co-Authored-By: Matthieu MOREL <mmorel-35@users.noreply.github.com>
2021-12-07 15:41:10 -07:00
Nelz 45e521ea93
enable composing PositionalArgs (#896)
* enable composing PositionalArgs
* ExactValidArgs slated for removal
* tests and docs
* rename to MatchAll
2021-12-07 15:38:00 -07:00
Unai Martinez-Corral 9e1d6f1c2a
args_test: add helper functions (#1426)
* args_test: add helper function expectSuccess
* args_test: add helper function getCommand
* args_test: add additional helper functions
* noArgsWithArgs
* validWithInvalidArgs
* minimumNArgsWithLessArgs
* maximumNArgsWithMoreArgs
* exactArgsWithInvalidCount
* rangeArgsWithInvalidCount
2021-11-16 15:20:18 -07:00
Unai Martinez-Corral 62a72cdd0f
fix(diff): use arg '--strip-trailing-cr' (#949)
In tests with diff, ignores trailing carriage returns (so tests pass on windows)
2021-11-16 15:17:12 -07:00
Yann Soubeyrand 442031e4ff
Allow specifying licenses using their SPDX identifier (#1159) 2021-11-15 13:39:40 -07:00
Steve Winslow 78969f9c81
Remove "Lesser" from header for GPL-2.0 template (#880)
This removes "Lesser" from the GPL-2.0 header template, since that header is meant to be referring to GPL-2.0 and not LGPL-2.0.

Fixes #879 

Signed-off-by: Steve Winslow <swinslow@gmail.com>
2021-11-15 13:33:16 -07:00
Nickolas Kraus 3c84bf8704
Small correction in User Guide (#1009) 2021-11-15 13:26:11 -07:00
Unai Martinez-Corral 3ba5f15ba7
Projects using cobra update (#1454)
* [projects_using_cobra] add moldy
* [projects_using_cobra] add UpCloud CLI (upctl)
* [projects_using_cobra] add scaleway-cli
* [projects_using_cobra] add qrcp
* [projects_using_cobra] add multi-gitter
* [projects_using_cobra] add Mercure
* [projects_using_cobra] add goreleaser and nfpm
* [projects_using_cobra] add Datree
* [projects_using_cobra] add Infracost
* [projects_using_cobra] add VMware Tanzu Framework

Co-authored-by: TeoDev1611 <malehurtadoreyes@hotmail.com>
Co-authored-by: Ville Skyttä <ville.skytta@upcloud.com>
Co-authored-by: Rémy Léone <rleone@scaleway.com>
Co-authored-by: Claudio d'Angelis <claudiodangelis@gmail.com>
Co-authored-by: Johan Lindell <johan@lindell.me>
Co-authored-by: Kévin Dunglas <dunglas@gmail.com>
Co-authored-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Co-authored-by: Yishay Mendelsohn <myishay@gmail.com>
Co-authored-by: Vadim Golub <github@vdmgolub.com>
Co-authored-by: Max Brauer <mamachanko@users.noreply.github.com>
2021-11-15 13:21:07 -07:00
Steve Francia bfacc59f62 Addressing typos identified by @marckhouzam 2021-11-03 15:36:51 -04:00
Steve Francia 26825627c2 Simplifying goGet function 2021-11-03 15:36:51 -04:00
Steve Francia cf87fc4e30 Updating generator documentation and links
Merging the updated documentation from the user_guide into the cobra/README.md.
Adding links as appropriate to both guides.
2021-11-03 15:36:51 -04:00
Steve Francia c97b7ece0b Update documentation to reflect the module aware generator 2021-11-03 15:36:51 -04:00
Steve Francia 9388e79fb4 Cobra generator now works within Go modules
Pretty major change in behavior, but with modules a change is needed.
Now cobra can initialize and add from within any Go module.
The experience is simplified and streamlined, but requires `go mod init` to happen first.
2021-11-03 15:36:51 -04:00
Steve Francia c9edb78acc Change generator default license to none
It's questionable that a default license makes any sense from a legal perspective.
If the tool created the license without the user choosing it, then it may not even be applicable.
Best to let the user choose their license with intent.
2021-11-03 15:36:51 -04:00
Steve Francia dcf42b25f7 Change generator to require opting in to viper.
Cobra and Viper are great together, but it's not uncommon to use them apart.
New Cobra users don't know better and including Viper by default adds complexity to the skeleton.
2021-11-03 15:36:51 -04:00