Commit graph

14 commits

Author SHA1 Message Date
Tom Payne 284f410104
Fix typo in fish completions (#1945) 2023-04-08 00:47:33 -04:00
Unai Martinez-Corral 9e6b58afc7
update copyright year (#1927) 2023-03-05 21:28:31 -05:00
Gyanendra Mishra 3daa4b9c36
Add keeporder to shell completion (#1903)
This allows programs to request the shell to maintain the order of completions that was returned by the program
2023-02-25 15:57:12 -05:00
Unai Martinez-Corral 6d978a911e
add missing license headers (#1809) 2022-09-16 07:55:56 -04:00
Marc Khouzam f464d6c82e
Add Active Help support (#1482) 2022-06-15 20:08:16 -04:00
Hugo 25f5bb5f97
Prefer ReplaceAll instead of Replace(..., -1) (#1530) 2022-05-14 14:10:36 -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 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 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 652c755d37
Use golangci-lint (#1044)
Use golangci-lint. Repair warnings and errors resulting from linting.
2021-02-07 17:08:50 -07: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
Marc Khouzam 675ae5f5a9
Fish does not accept - or : in vars (#1122)
Fixes #1121.
This is for programs that may contain a : or - in their name.

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
2020-07-10 14:12:46 -06:00
Marc Khouzam 2c5a0d300f
Extend Go completions and revamp zsh comp (#1070) (#1070)
Replace the current Zsh completion with a Zsh completion solution based
on Go completions. This allows to support custom completions (based
on Go completions), but also to standardize the behavior of completion
across all shells.

Also, add support to Go completions for the bash completion annotations:
  BashCompFilenameExt (including Command.MarkFlagFilename() family)
                       - still supported by zsh
  BashCompSubdirsInDir - now supported by zsh
  BashCompOneRequiredFlag (including Command.MarkFlagRequired() family)
                       - now supported by zsh and fish

Finally, remove the suggestin of the = form of flag completion.
The = form is supported, but it will not be suggested to avoid having
duplicated suggestions.
2020-06-29 13:52:14 -06:00
Marc Khouzam a684a6d7f5
Fish completion using Go completion (#1048)
Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
2020-04-10 13:56:28 -06:00