Fix completion bug, ensure_async callback

This commit is contained in:
2025-07-21 00:11:21 -04:00
parent 0319058531
commit de53c889a6
5 changed files with 11 additions and 6 deletions

View File

@ -86,7 +86,7 @@ class FalyxCompleter(Completer):
if not command.arg_parser:
return
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:
if suggestion.startswith(stub):

View File

@ -64,7 +64,7 @@ from falyx.protocols import ArgParserProtocol
from falyx.retry import RetryPolicy
from falyx.signals import BackSignal, CancelSignal, HelpSignal, QuitSignal
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__
@ -1091,7 +1091,8 @@ class Falyx:
if callback:
if not callable(callback):
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"):
self.options.set("never_prompt", self._never_prompt)

View File

@ -1018,7 +1018,9 @@ class CommandArgumentParser:
kwargs_dict[arg.dest] = parsed[arg.dest]
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.
@ -1026,6 +1028,7 @@ class CommandArgumentParser:
Args:
args (list[str]): Current partial argument tokens.
cursor_at_end_of_token (bool): True if space at end of args
Returns:
list[str]: List of suggested completions.
@ -1096,6 +1099,7 @@ class CommandArgumentParser:
and last not 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 not cursor_at_end_of_token
):
suggestions.extend(arg.suggestions)
else:

View File

@ -1 +1 @@
__version__ = "0.1.67"
__version__ = "0.1.68"

View File

@ -1,6 +1,6 @@
[tool.poetry]
name = "falyx"
version = "0.1.67"
version = "0.1.68"
description = "Reliable and introspectable async CLI action framework."
authors = ["Roland Thomas Jr <roland@rtj.dev>"]
license = "MIT"