Commit Graph

923 Commits

Author SHA1 Message Date
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
Unai Martinez-Corral b73b344b63
ci: add GitHub Actions workflow 'Test' (#1339)
Adds a "test" action which will run side by side (for now) with Travis

Co-authored-by: John McBride <jpmmcbride@gmail.com>
2021-02-09 08:48:59 -07:00
Unai Martinez-Corral 652c755d37
Use golangci-lint (#1044)
Use golangci-lint. Repair warnings and errors resulting from linting.
2021-02-07 17:08:50 -07:00
Joshua Harshman 1d71ff0270
Deprecate Go < 1.14 (#1323)
In accordance with our adopted best practices, the main branch and the
next major release of Cobra will deprecate older and un-maintained
versions of Golang.

fix #1322
2021-02-01 15:59:47 -07:00
Anthony Fok 1135bdeceb
Update gopkg.in/yaml.v2 to v2.4.0
The previous breaking change in yaml.v2 v2.3.0 has been reverted,
see https://github.com/go-yaml/yaml/pull/670
2021-02-01 12:44:33 -07:00
Joshua Harshman 9df156e6d1
Cobra User Contract (#1292)
* Add some guiding principals to the project.

Establish an understanding between user and maintainer.
Set a goal for releases, security fixes and bug patches.

* fix grammatical errors
2021-01-26 10:55:24 -07:00
John McBride ff416ad438
Revert "Add the ability to specify a filePostpender in GenMarkdownTreeCustom (#1270)" (#1317)
This reverts commit 23a6174c7f.
2021-01-23 16:05:55 -07:00
Joon-Ho Son 23a6174c7f
Add the ability to specify a filePostpender in GenMarkdownTreeCustom (#1270) 2021-01-20 20:33:16 -07:00
Maxime Bury 4384b91fb4
Bump license year to 2021 in golden files (#1309)
* Update main.go.golden

* Update root.go.golden

* Update test.go.golden
2021-01-16 20:41:43 -05:00
Paul Holzinger a4ab3fa09e
powershell completion with custom comp (#1208)
The current powershell completion is not very capable.

Let's port it to the go custom completion logic to have a
unified experience accross all shells.

Powershell supports three different completion modes

- TabCompleteNext (default windows style - on each key press the next option is displayed)
- Complete (works like bash)
- MenuComplete (works like zsh)

You set the mode with `Set-PSReadLineKeyHandler -Key Tab -Function <mode>`

To keep it backwards compatible `GenPowerShellCompletion` will not display descriptions.
Use `GenPowerShellCompletionWithDesc` instead. Descriptions will only be displayed with
`MenuComplete` or `Complete`.

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
2020-12-29 07:57:32 -07:00
Jon Love 471c9ac367
Add the new Twitch CLI to to projects_using_cobra.md (#1301) 2020-12-29 07:39:22 -07:00
namusyaka 7df62f7668
fix typos (#1274) 2020-12-04 12:34:11 -07:00
zaataylor 39b5a91b20
README.md Readability Improvements (#1228)
I made some small changes to the README.md file to enhance its readability.
2020-12-04 12:15:09 -07:00
Vincent 08c51e585c
Add ORY Hydra & Kratos to projects_using_cobra.md (#1273)
* Add ORY Hydra & Kratos to projects_using_cobra.md

* fix: alphabetical order

my bad!

* fix: ORY to Ory

I think now it should be good, 
sorry for the confusion!
2020-11-09 16:46:15 -07:00
Sascha Steinbiss 86f8bfd7fe
fix manpage building with new go-md2man (#1255)
This addresses #1049 by changing the format of the generated
Markdown input.
2020-10-18 12:59:26 -06:00
Marc Khouzam f32f4ef15b
Don't use yaml.v2 2.3.0 which has a breaking change (#1259)
yaml.v2 contains a breaking change from
https://github.com/go-yaml/yaml/pull/571

yaml.v2 2.2.8 does not have that change and also addresses the CVE that
was behind the move to yaml.v2 2.3.0.  This commit reverts to using
yaml.v2 2.2.8

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
2020-10-18 12:50:48 -06:00
Adam Demuri 142dfb15a8
Add example for making persistent flags required (#1135) 2020-10-14 09:53:09 -06:00
Alessio Treglia 723d0c36fc
Add tendermint and cosmos-sdk to the list of projects using cobra (#855)
* Add tendermint and cosmos-sdk to the list of projects using cobra

Co-authored-by: Steve Francia <steve.francia@gmail.com>
2020-10-14 09:51:35 -06:00
Matej Vasek b97b5ead31
fix: fish output redirection (#1247)
Signed-off-by: Matej Vasek <mvasek@redhat.com>
2020-10-05 21:54:06 -06:00
midchildan f64bfa1e08
Fix zsh completion not working on the first time in a shell session (#1237)
The zsh completion script output by cobra is a stub completion function
which replaces itself with the actual completion function. This
technique enables cobra to define helper functions without splitting the
completion script into multiple files.  However, the current
implementation forgets to call the actual completion function at the end
of the stub function, meaning that completion won't work the first time
it's invoked in a shell session. This commit is a fix for this problem.
2020-10-03 19:25:07 -06:00
Alessio Treglia 40d34bca1b
Fix stderr printing functions (#894)
* Fix stderr printing functions

Follow-up of #822

* Errors go to stderr as per POSIX

* use PrintErrf() instead of extra call to Sprintf()

* Error messages should always be printed to os.Stderr.

* add test case for Print* redirection

Thanks: @bukowa for the patch.
2020-10-01 09:28:00 -06:00
John McBride 0bc8bfbe59
Remove secondary go mod to prevent broken `go get` (#1233) 2020-09-23 16:26:21 -06:00
Danny Hermes 7f8e83d936
Modifying "snake-case" to "kebab-case" for clarity. (#1196) 2020-09-16 09:27:58 -06:00
Arda Aytekin 8a39cb2614
Bug fix in README (#1199)
Bug fixed in `README.md`.
2020-09-16 09:26:27 -06:00
Fabrício José Souza 2a8d0f327d
Adding Kool to list of projects using cobra (#1224) 2020-09-15 08:45:35 -06:00
Umberto Baldi 6c06523c96
add arduino-cli to projects using cobra (#1117)
* add arduino-cli to projects using cobra
2020-09-15 08:44:32 -06:00
Luap99 8a63648dd9
Handle linebreaks in custom completions. (#1162)
If a command/flag description contains
a linebreak then the shell completion script
will interpret this as new command/flag.

To fix this we only use the first line
from the description in the output.

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
2020-09-09 11:27:42 -06:00
Luap99 50258f15eb
Complete subcommands when TraverseChildren is set (#1171)
* Complete subcommands when TraverseChildren is true in custom completion

The current custom completion logic does not complete
subcommands when a local flag is set. This is good unless
TraverseChildren is set to true where local flags
can be set on parent commands.

This commit allows subcommands to be completed
if TraverseChildren is set to true on the root cmd.

Closes #1170

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>

* Complete subcommands when TraverseChildren is true in bash completion

The current bash completion logic does not complete
subcommands when a local flag is set. There is also a bug
where subcommands are sometimes still getting completed. see: #1172

If TraverseChildren is true we should allow subcommands
to be completed even if a local flag is set.

Closes #1172

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
2020-09-09 09:34:51 -06:00
Marc Lopez Rubio 02a0d2fbc9
doc: GenMarkdown skip Synopsis on empty long cmd (#1207)
This patch modifies the GenMarkdownCustom to skip writing a Synopsis
header with the `cmd.Short` duplicated both before and after the header.

Instead, it only writes the `### Synopsis` header and the paragraph when
a `cmd.Long` has some kind of content in it.

Adds `TestGenMdDocWithNoLongOrSynopsis` as the test case.

Signed-off-by: Marc Lopez <marc5.12@outlook.com>
2020-08-26 09:18:51 -06:00
Joshua Harshman 9ed1d713d6
bugfix/cli: Temporary fix for go get on cobra cli (#1200)
PR #1139 introduced a complexity that will have to be taken into account
as we figure out our release pipeline. This fix pins to cobrav1.0.0 as a
temporary workaround.

fixes: #1191
2020-08-23 13:45:41 -04:00
Michael Muré 8cfa4b4acf
Add documentation for Use (#1188) 2020-08-18 14:14:09 -06:00
Michael Muré 81e0311edd
modules: add a secondary go.mod to segregate CLI dependencies (#1139) 2020-08-15 10:44:17 -04:00