Commit Graph

1054 Commits

Author SHA1 Message Date
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
silenceshell 3c8a19ecd3
fix RegisterFlagCompletionFunc concurrent map writes error (#1423)
* fix-RegisterFlagCompletionFunc-concurrent
* set to root command
* move to non-public fields
2021-06-30 15:49:30 -06:00
John McBride 2dea4f2ef3
Bump to viper 1.8.1 (#1433) 2021-06-30 15:45:46 -06:00
Marc Khouzam b36196066e
Bash completion V2 with completion descriptions (#1146)
* Bash completion v2

This v2 version of bash completion is based on Go completions.
It also supports descriptions like the other shells.

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>

* Only consider matching completions for formatting

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>

* Use bash compV2 for the default completion command

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>

* Update comments that still referred to bash completion

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
2021-06-30 15:24:58 -06:00
umarcor d0f318d45b ci: deprecate Travis CI 2021-06-30 16:38:08 -04:00
umarcor 8eaca5f0f4 drop mitchellh/go-homedir (#853) 2021-06-30 14:08:43 -04:00
umarcor ace6b14345 readme: split 'Getting Started' into 'user_guide.md' 2021-06-30 12:46:37 -04:00
Mark Sagi-Kazar 701fa6c2be chore(deps): update viper
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
2021-06-30 12:41:17 -04:00
Rob Playford 9a432671fd
fix home directory config not loading (#1282)
leverage `viper.SetConfigType("yaml")` to fix issue regarding home directory configuration failing to load.
2021-06-15 19:52:13 -06:00
tamo 4590150168
Correcting misspelled words (#1349)
* Correcting Misspelled Words
* grammar fixes
2021-05-10 17:19:33 -06:00
Marc Khouzam c2e21bdc10
Fix multiple fish completion issues (#1249)
* Fix fish for ShellDirectiveNoSpace and file comp

For fish shell we achieve ShellDirectiveNoSpace by outputing a fake
second completion with an extra character.  However, this extra
character was being added after the description string, instead of
before.  This commit fixes that.

It also cleans up the script of useless code, now that fish completion
details are better understood.

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>

* Handle case when completion starts with a space

Fixes #1303

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>

* Support fish completion with env vars in the path

Fixes https://github.com/spf13/cobra/issues/1214
Fixes https://github.com/spf13/cobra/issues/1306

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>

* Update based on review

1- We use `set -l` for local variable to make sure there are no
   conflicts with global variables
2- We use `commandline -opc` which:
   a) splits the command line into tokens (-o)
   b) only considers the current command (-p) (e.g., echo hello; helm <TAB>)
   c) stops at the cursor (-c)
3- We extract the last arg with `commandline -ct` and escape it to handle
   the case where it is a space, or unmatched quote.
4- We avoid looping when filtering on prefix.
5- We don't add a fake comp for ShellCompDirectiveNoSpace when the
   completion ends with any of @=/:., as fish won't add a space

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
2021-05-03 12:00:01 -06:00
Marc Khouzam 95d23d24ff
Fix zsh for DirectiveNoSpace and DirectiveNoFileComp (#1213)
Fixes #1211

When handling ShellCompDirectiveNoSpace we must still properly handle
descriptions.  To do so we cannot simply use 'compadd', but must use
zsh's '_describe' function.

Also, when handling ShellCompDirectiveNoSpace we cannot assume that
only a single completion will be given to the script.  In fact,
ValidArgsFunction can return multiple completions, even if they don't
match the 'toComplete' argument prefix.  Therefore, we cannot use the
number of completions received in the completion script to determine
if we should activate the "no space" directive.  Instead, we can leave
it all to the '_describe' function.

Fixes #1212

When handling ShellCompDirectiveNoFileComp we cannot base ourself on
the script receiving no valid completion. In fact,
ValidArgsFunction can return multiple completions, even if they don't
match the 'toComplete' argument prefix at all.  Therefore, we cannot use
the number of completions received by the completion script to determine
if we should activate the "no file comp" directive.  Instead, we can
check if the '_describe' function has found any completions.

Finally, it is important for the script to return the return code of the
called zsh functions (_describe, _arguments).  This tells zsh if
completions were found or not, which if not, will trigger different
matching attempts, such as matching what the user typed with the the
content of possible completions (instead of just as the prefix).

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
2021-05-03 10:54:00 -06:00
Paul Holzinger 2d94892a8b
Custom completion handle multiple shorhand flags together (#1258)
Flag definitions like `-asd` are not handled correctly by
the custom completion logic. They should be treated as
multiple flags. For details refer to #1257.

Fixes #1257

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
2021-05-03 10:42:00 -06:00
Lukas Malkmus 6d00909120
Pass context to completion (#1265) 2021-05-03 10:33:57 -06:00
Paul Holzinger 7223a997c8
powershell completion fix no file comp directive (#1363)
Make sure to filter the returned completions before we check if
there are valid completions left.

Fixes #1362

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
2021-05-03 10:25:30 -06:00
Marc Khouzam 06e4b59b20
Allow fish comp to support trailing empty lines (#1284)
Some programs may output extra empty lines after the directive.
Those lines must be ignored for fish shell completion to work.
zsh and bash are not impacted.

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
Co-authored-by: Johannes Altmanninger <aclopte@gmail.com>

Co-authored-by: Johannes Altmanninger <aclopte@gmail.com>
2021-05-03 10:23:34 -06:00
Unai Martinez-Corral 3ed6a394b6
ci/MSYS2: go install @latest (#1366) 2021-05-03 10:08:39 -06:00
Ville Skyttä eb3b6397b1
Bash completion variable leak fixes (#1352)
Fixes bash variables leaking into the parent shell without `local`
2021-02-18 08:26:03 -07:00
John McBride b55fa79836
Add PR labeler with pull_request_target (#1338)
* Add PR labeler with pull_request_target
2021-02-15 10:48:09 -07:00
Marc Khouzam b312f0a8ef
Create 'completion' command automatically (#1192)
Make it easier for programs to provide shell completion by creating
the 'completion' command automatically.

If a 'completion' command is already provided by the program, Cobra
will use that one instead.

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
2021-02-15 10:47:01 -07:00
Paul Holzinger ded486a867
Fix trailing whitespace in the powershell completion script (#1342)
Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
2021-02-14 10:27:21 -07:00
Anthony Fok 893ebf6e36
Fix typo 2021-02-10 12:40:59 -07:00
Anthony Fok be1efc850f
Update CHANGELOG.md for v1.1.3 2021-02-10 12:35:57 -07:00
Anthony Fok 7f95502478
Update CHANGELOG.md for v1.1.2 2021-02-09 18:39:00 -07:00
Anthony Fok 07445ea179
Copyedit shell-completion related documentation 2021-02-09 14:08:42 -07:00