Commit graph

1028 commits

Author SHA1 Message Date
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
Steve Francia
c0dd5cdef5 Removing unused imports when not using Viper 2021-11-03 15:36:51 -04:00
Unai Martinez-Corral
f09e947637
readme: remove ToC, since it's now shown by GitHub (#1429) 2021-11-02 09:10:14 -06:00
Marc Khouzam
d2c0cb310d
DisableFlagParsing must disable flag completion (#1161)
When a command has set DisableFlagParsing=true, it means Cobra should
not be handling flags for that command but should let the command
handle them itself.  In fact, Cobra normally won't have been told at all
about flags for this command.

Not knowing about the flags of the command also implies that Cobra
cannot perform flag completion as it does not have the necessary info.

This commit still tries to do flag name completion, but when
DisableFlagParsing==true, it continues on so that ValidArgsFunction will
be called; this allows the program to handle completion for its own
flags when DisableFlagParsing==true.

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
2021-11-01 13:01:33 -06:00
John McBride
c1973d31bf
Update projects-using markdown with Tanzu (#1501)
Signed-off-by: John McBride <jmcbride@vmware.com>
2021-10-04 14:58:08 -06:00
Unai Martinez-Corral
4fd30b69ee
ci: test golang 1.16.x and 1.17.x too (#1425)
* ci: test golang 1.16.x too

* ci: style

* ci: test golang 1.17.x too

* bump go.mod to 1.15

* run gofmt
2021-08-25 21:18:53 -06:00
Sebastiaan van Stijn
2a5277810f
go.mod: cpuguy83/go-md2man/v2 v2.0.1 (#1460)
full diff: https://github.com/cpuguy83/go-md2man/compare/v2.0.0...v2.0.1

- Fix handling multiple definition descriptions
- Fix inline markup causing table cells to split
- Remove escaping tilde character (prevents tildes (`~`) from disappearing).
- Do not escape dash, underscore, and ampersand (prevents ampersands (`&`) from disappearing).
- Ignore unknown HTML tags to prevent noisy warnings

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-08-05 11:08:25 -06:00
Raúl Barroso
56060d19f8
Add Meroxa CLI (#1377)
👋,

I'm reaching out in behalf of [Meroxa](https://meroxa.com/) as one of its developers. We've been using [Cobra](https://github.com/spf13/cobra) since our first [initial commit](meroxa/cli@a3301a0) back from January 2020, and we recently [launched our Platform](https://techcrunch.com/2021/04/13/meroxa-raises-15m-series-a-for-its-real-time-data-platform/) to the public.

We continue considering using Cobra as our CLI framework and are [actively](https://github.com/meroxa/cli/releases) working on it, and it'd be really nice to be featured as one of the projects using Cobra in the wild.

Thank you!
2021-08-02 08:19:25 -06:00
Paul Holzinger
de187e874d
Fix flag completion (#1438)
* Fix flag completion

The flag completion functions should not be stored in the root cmd.
There is no requirement that the root cmd should be the same when
`RegisterFlagCompletionFunc` was called. Storing the flags there does
not work when you add the the flags to your cmd struct before you add the
cmd to the parent/root cmd. The flags can no longer be found in the rigth
place when the completion command is called and thus the flag completion
does not work.

Also #1423 claims that this would be thread safe but we still have a map
which will fail when accessed concurrently. To truly fix this issue use a
RWMutex.

Fixes #1437
Fixes #1320

Signed-off-by: Paul Holzinger <pholzing@redhat.com>

* Fix trailing whitespaces in fish comp scripts

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2021-07-02 09:25:47 -06:00
Marc Khouzam
07861c800d
Fix documentation (#1434)
Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
2021-07-01 09:49:30 -06:00
Kyle Lemons
5738d6b72d
Add install instructions for zsh on Mac OS (#1417)
zsh is now the default on Mac OS, but the $_fpath version of the installation instructions are likely to put the completion in a strange location that the user might not expect (e.g. an oh-my-zsh plugin's function directory).  So, since Mac OS seems to (as far as I can tell) provide a stable location, this PR recommends using that path instead.
2021-07-01 09:49:12 -06:00
Paul Holzinger
5d46ac904d
custom comp: do not complete flags after args when interspersed is false (#1308)
If the interspersed option is set false and one arg is already set all
following arguments are counted as arg and not parsed as flags. Because
of that we should not offer flag completion. The same applies to arguments
followed after `--`.

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
2021-07-01 09:47:10 -06:00