diff --git a/falyx/completer.py b/falyx/completer.py index eef6cd8..9b6d289 100644 --- a/falyx/completer.py +++ b/falyx/completer.py @@ -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): diff --git a/falyx/falyx.py b/falyx/falyx.py index 35a9867..11e1de5 100644 --- a/falyx/falyx.py +++ b/falyx/falyx.py @@ -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) diff --git a/falyx/parser/command_argument_parser.py b/falyx/parser/command_argument_parser.py index 132eecc..88d5e0a 100644 --- a/falyx/parser/command_argument_parser.py +++ b/falyx/parser/command_argument_parser.py @@ -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: diff --git a/falyx/version.py b/falyx/version.py index 69f79d2..613d040 100644 --- a/falyx/version.py +++ b/falyx/version.py @@ -1 +1 @@ -__version__ = "0.1.67" +__version__ = "0.1.68" diff --git a/pyproject.toml b/pyproject.toml index 7418846..45e0559 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] license = "MIT"