Commit graph

21 commits

Author SHA1 Message Date
PapaCharlie
ee1287cc3f Use the empty string as a parameter to the flag being completed
Also attempt to standardize the bash and zsh implementations

Next up: tests!
2020-02-21 10:14:45 -08:00
PapaCharlie
53e4e28648 Remove extra splat for zsh arrays
It turns out that zsh will simply use the elements of an array as the parameters when referenced in
the shell without quotes
```
% cat t.py
import sys
print sys.argv

% typeset -a args
% args+=("./t.py")
% args+=("123
321")
% $args
['./t.py', '123\n321']
```
2020-02-21 10:14:45 -08:00
PapaCharlie
979059b9c4 Implement bash completions! 2020-02-21 10:14:45 -08:00
PapaCharlie
c87d78cfc6 Add framework for dynamic tab completions
By setting the COBRA_FLAG_COMPLETION environment variable, the normal execution path of the command
is short circuited, and instead the function registered by `MarkCustomFlagCompletion` is executed.

All flags other than the one being completed get parsed according to whatever type they are defined
as, but the flag being completed is parsed as a raw string and passed into the custom compeltion.
2020-02-21 10:14:45 -08:00
Haim Ashkenazi
e2c45ac9eb Started working on Unified API for the various shell completions:
- Moved some general function to a more generic shell_completions file.
- Added functions to mark flag as directory completion.
- Started making the global functions docs more generic (not bash
  specific) and added compatibility matrix.
2019-06-07 10:09:50 -04:00
Haim Ashkenazi
edbb6712e2 zsh-completions: implemented argument completion. 2019-06-07 10:09:50 -04:00
Haim Ashkenazi
d262154093 zsh-completion: tidy up function and variable names
There are many files in the package, renamed all zsh-completion
related names to convey that.
2019-06-07 10:09:50 -04:00
Haim Ashkenazi
8822449c0f zsh-completion: added escapinng of single quotes in flag description. 2019-06-07 10:09:50 -04:00
Haim Ashkenazi
7ce08e227e zsh-completion: completion should always parse the root command!
It was running on the command it was invoked from which caused some
additional helpers (--help, --version) not to be generated.
2019-06-07 10:09:50 -04:00
Haim Ashkenazi
50f385938e zsh-completion: added support for filename globbing. 2019-06-07 10:09:50 -04:00
Haim Ashkenazi
461a39d5b9 zsh-completion: removed forgotten function. 2019-06-07 10:09:50 -04:00
Haim Ashkenazi
df12a0a249 zsh-completion: two fixes for identifying flag usage:
Fixed after input from @eparis:
- Decide on option parameter by checking NoOptDefVal
- Slices also could be specified multiple times.
2019-06-07 10:09:50 -04:00
Haim Ashkenazi
ec4b8c974c zsh-completions: revised flags completion rendering + new features:
- If the flags are not bool the completion expects argument.
- You don't have to specify file extensions for file completion to
  work.
- Allow multiple occurrences of flag if type is stringArray.

Need to verify that these assumption are correct :)
2019-06-07 10:09:50 -04:00
Haim Ashkenazi
e8018e8612 zsh-completion template refactoring:
- removed redundant function
- improved other functions :)
- better names for other functions
2019-06-07 10:09:50 -04:00
Haim Ashkenazi
2662787697 zsh-completion: added support for subcommand description.
Also make the template more elegant on the way...
2019-06-07 10:09:50 -04:00
Haim Ashkenazi
f0508c8e76 zsh-completion ignores hidden commands and flags :) 2019-06-07 10:09:50 -04:00
Haim Ashkenazi
a15d099018 zsh-completion fixed reference to cmd name
cmd.Use is not the command name :). Found it once I figured out
that I need to execute the command in order to fully test the
generated completion.
2019-06-07 10:09:50 -04:00
Haim Ashkenazi
7e2436b79d First try at better zsh completions:
A very basic POC. Need to refactor to generate completion
structure before passing to the template to avoid repeated
computations.

What works:
  * Real zsh completion (not built on bash)
  * Basic flags (with long flag and optional shorthand)
  * Basic filename completion indication (not with file extensions though)

What's missing:
  * File extensions to filename completions
  * Positional args
  * Do we require handling only short flags?
2019-06-07 10:09:50 -04:00
Eric Paris
b787445794 Use func (c *Command) consistently (#530)
It makes the docs looks better. The idea was suggested by @SamWhited
2017-09-05 13:20:51 -04:00
agmen
4de692c1eb adding a GenZshCompletionFile function to mirror bash_completion (#529) 2017-09-05 12:32:32 -04:00
bpicode
d7ba19510d Add basic zsh completion (command hierarchy only)
Partially fixes #107
See PR #497
2017-07-30 02:44:28 -06:00