Fix completion bug, ensure_async callback
This commit is contained in:
@ -86,7 +86,7 @@ class FalyxCompleter(Completer):
|
|||||||
if not command.arg_parser:
|
if not command.arg_parser:
|
||||||
return
|
return
|
||||||
suggestions = command.arg_parser.suggest_next(
|
suggestions = command.arg_parser.suggest_next(
|
||||||
parsed_args + ([stub] if stub else [])
|
parsed_args + ([stub] if stub else []), cursor_at_end_of_token
|
||||||
)
|
)
|
||||||
for suggestion in suggestions:
|
for suggestion in suggestions:
|
||||||
if suggestion.startswith(stub):
|
if suggestion.startswith(stub):
|
||||||
|
@ -64,7 +64,7 @@ from falyx.protocols import ArgParserProtocol
|
|||||||
from falyx.retry import RetryPolicy
|
from falyx.retry import RetryPolicy
|
||||||
from falyx.signals import BackSignal, CancelSignal, HelpSignal, QuitSignal
|
from falyx.signals import BackSignal, CancelSignal, HelpSignal, QuitSignal
|
||||||
from falyx.themes import OneColors
|
from falyx.themes import OneColors
|
||||||
from falyx.utils import CaseInsensitiveDict, _noop, chunks
|
from falyx.utils import CaseInsensitiveDict, _noop, chunks, ensure_async
|
||||||
from falyx.version import __version__
|
from falyx.version import __version__
|
||||||
|
|
||||||
|
|
||||||
@ -1091,7 +1091,8 @@ class Falyx:
|
|||||||
if callback:
|
if callback:
|
||||||
if not callable(callback):
|
if not callable(callback):
|
||||||
raise FalyxError("Callback must be a callable function.")
|
raise FalyxError("Callback must be a callable function.")
|
||||||
callback(self.cli_args)
|
async_callback = ensure_async(callback)
|
||||||
|
await async_callback(self.cli_args)
|
||||||
|
|
||||||
if not self.options.get("never_prompt"):
|
if not self.options.get("never_prompt"):
|
||||||
self.options.set("never_prompt", self._never_prompt)
|
self.options.set("never_prompt", self._never_prompt)
|
||||||
|
@ -1018,7 +1018,9 @@ class CommandArgumentParser:
|
|||||||
kwargs_dict[arg.dest] = parsed[arg.dest]
|
kwargs_dict[arg.dest] = parsed[arg.dest]
|
||||||
return tuple(args_list), kwargs_dict
|
return tuple(args_list), kwargs_dict
|
||||||
|
|
||||||
def suggest_next(self, args: list[str]) -> list[str]:
|
def suggest_next(
|
||||||
|
self, args: list[str], cursor_at_end_of_token: bool = False
|
||||||
|
) -> list[str]:
|
||||||
"""
|
"""
|
||||||
Suggest completions for the next argument based on current input.
|
Suggest completions for the next argument based on current input.
|
||||||
|
|
||||||
@ -1026,6 +1028,7 @@ class CommandArgumentParser:
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
args (list[str]): Current partial argument tokens.
|
args (list[str]): Current partial argument tokens.
|
||||||
|
cursor_at_end_of_token (bool): True if space at end of args
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list[str]: List of suggested completions.
|
list[str]: List of suggested completions.
|
||||||
@ -1096,6 +1099,7 @@ class CommandArgumentParser:
|
|||||||
and last not in arg.suggestions
|
and last not in arg.suggestions
|
||||||
and not any(last.startswith(suggestion) for suggestion in arg.suggestions)
|
and not any(last.startswith(suggestion) for suggestion in arg.suggestions)
|
||||||
and any(suggestion.startswith(last) for suggestion in arg.suggestions)
|
and any(suggestion.startswith(last) for suggestion in arg.suggestions)
|
||||||
|
and not cursor_at_end_of_token
|
||||||
):
|
):
|
||||||
suggestions.extend(arg.suggestions)
|
suggestions.extend(arg.suggestions)
|
||||||
else:
|
else:
|
||||||
|
@ -1 +1 @@
|
|||||||
__version__ = "0.1.67"
|
__version__ = "0.1.68"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "falyx"
|
name = "falyx"
|
||||||
version = "0.1.67"
|
version = "0.1.68"
|
||||||
description = "Reliable and introspectable async CLI action framework."
|
description = "Reliable and introspectable async CLI action framework."
|
||||||
authors = ["Roland Thomas Jr <roland@rtj.dev>"]
|
authors = ["Roland Thomas Jr <roland@rtj.dev>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
Reference in New Issue
Block a user