pyparam.completer
Classes for completions
The idea is inspired from https://github.com/pallets/click/pull/1622
Some of the code is borrowing there, under following LICENSE:
Copyright 2014 Pallets
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Completer
— Main completion handler</>CompleterParam
— Class for a parameter dealing with completion</>
split_arg_string
(
string
)
(list of str) — Given an argument string this attempts to split it into small parts.</>
pyparam.completer.
split_arg_string
(
string
)
Given an argument string this attempts to split it into small parts.
Borrowed from https://github.com/pallets/click/blob/3984f9efce5a0d15f058e1abe1ea808c6abd243a/src/click/parser.py#L106
string
(str) — The string to be split
List of split pieces
pyparam.completer.
Completer
(
)
Main completion handler
comp_curr
(str) — The current word for completioncomp_prev
(str) — The previous word matchedcomp_shell
(str) — The shell where the completion will be conducted One of ['', 'bash', 'fish', 'zsh'] Obtained from environmentcomp_words
(list of str) — The words have been entered before completionprogvar
(str) — Get the program name that can be used as a variable</>uid
(str) — Get the uid based on the raw program name
This is used as the prefix or suffix of some shell function names</>
shellcode
(
shell
, python=None
, module=False
)
→ str
Generate the shell code to be integrated
For bash, it should be appended to ~/.profile
For zsh, it should be appended to ~/.zprofile
For fish, it should be appended to
~/.config/fish/completions/%(prog)s.fish
If python is provided, this should go to python.fish
rather than
the %(prog)s.fish
shell
(str) — The shell to generate the code for.python
(str, optional) — The python name or path to invoke completion.module
(bool, optional) — Whether do completion forpython -m <prog>
ValueError
— if shell is not one of bash, zsh and fish
complete
(
)
Yields the completions
The strings as completion candidates
pyparam.completer.
CompleterParam
(
)
Class for a parameter dealing with completion
complete_name
(
current
)
(iterator of (str, str)) — Give the completion name candidates</>complete_value
(
current
,prefix
)
(Union(str, iterator of (str, ...))) — Give the completion candidates</>
complete_value
(
current
, prefix=''
)
Give the completion candidates
current
(str) — Current prefix
None when there are no candidates, nor should we have next paramters/commands as candidates (requiring a value). An empty string if we should put next parameters/commands as candidates. Otherwise yields The candidates should be either 1-, 2-, or 3-element tuple. If 1-element, type plain and no description implied. If 2-element, type plain and 2nd element should be description. If 3-element, 2nd element the type, 3rd the description.
complete_name
(
current
)
Give the completion name candidates
current
(str) — The current prefix or word under cursor
An iterator of a tuple including the prefixed name and description.