Commit graph

6 commits

Author SHA1 Message Date
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
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
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
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
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
Renamed from custom_completions_test.go (Browse further)