From 079bc0ee77e6374badd4c270731673044e978472 Mon Sep 17 00:00:00 2001 From: Roland Thomas Date: Sun, 1 Jun 2025 23:02:35 -0400 Subject: [PATCH] Normalize epilogue -> epilog, allow version to be modifiable, don't allow empty input in repl --- examples/falyx_demo.py | 7 ------- falyx/__main__.py | 2 +- falyx/command.py | 4 ++-- falyx/config.py | 2 +- falyx/falyx.py | 13 ++++++++++--- falyx/parsers/argparse.py | 10 +++++----- falyx/version.py | 2 +- pyproject.toml | 2 +- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/examples/falyx_demo.py b/examples/falyx_demo.py index fc33a35..757f5a2 100644 --- a/examples/falyx_demo.py +++ b/examples/falyx_demo.py @@ -74,17 +74,10 @@ class Foo: await self.flx.run() -def parse_args() -> Namespace: - parsers: FalyxParsers = get_arg_parsers() - return parsers.parse_args() - - async def main() -> None: """Build and return a Falyx instance with all your commands.""" - args = parse_args() flx = Falyx( title="🚀 Falyx CLI", - cli_args=args, columns=5, welcome_message="Welcome to Falyx CLI!", exit_message="Goodbye!", diff --git a/falyx/__main__.py b/falyx/__main__.py index 7978b95..0583c3c 100644 --- a/falyx/__main__.py +++ b/falyx/__main__.py @@ -97,7 +97,7 @@ def main() -> Any: init_project, aliases=["init"], argument_config=init_config, - help_epilogue="If no name is provided, the current directory will be used.", + help_epilog="If no name is provided, the current directory will be used.", ) flx.add_command( "G", diff --git a/falyx/command.py b/falyx/command.py index 65a2f3d..a77ff50 100644 --- a/falyx/command.py +++ b/falyx/command.py @@ -111,7 +111,7 @@ class Command(BaseModel): hidden: bool = False aliases: list[str] = Field(default_factory=list) help_text: str = "" - help_epilogue: str = "" + help_epilog: str = "" style: str = OneColors.WHITE confirm: bool = False confirm_message: str = "Are you sure?" @@ -233,7 +233,7 @@ class Command(BaseModel): command_description=self.description, command_style=self.style, help_text=self.help_text, - help_epilogue=self.help_epilogue, + help_epilog=self.help_epilog, aliases=self.aliases, ) for arg_def in self.get_argument_definitions(): diff --git a/falyx/config.py b/falyx/config.py index 2ead886..4e2a3ec 100644 --- a/falyx/config.py +++ b/falyx/config.py @@ -102,7 +102,7 @@ class RawCommand(BaseModel): retry_policy: RetryPolicy = Field(default_factory=RetryPolicy) hidden: bool = False help_text: str = "" - help_epilogue: str = "" + help_epilog: str = "" @field_validator("retry_policy") @classmethod diff --git a/falyx/falyx.py b/falyx/falyx.py index bb95171..585cfd4 100644 --- a/falyx/falyx.py +++ b/falyx/falyx.py @@ -88,6 +88,11 @@ class CommandValidator(Validator): async def validate_async(self, document) -> None: text = document.text + if not text: + raise ValidationError( + message=self.error_message, + cursor_position=len(text), + ) is_preview, choice, _, __ = await self.falyx.get_command(text, from_validate=True) if is_preview: return None @@ -157,6 +162,7 @@ class Falyx: description: str | None = "Falyx CLI - Run structured async command workflows.", epilog: str | None = None, version: str = __version__, + version_style: str = OneColors.BLUE_b, prompt: str | AnyFormattedText = "> ", columns: int = 3, bottom_bar: BottomBar | str | Callable[[], Any] | None = None, @@ -180,6 +186,7 @@ class Falyx: self.description: str | None = description self.epilog: str | None = epilog self.version: str = version + self.version_style: str = version_style self.prompt: str | AnyFormattedText = prompt self.columns: int = columns self.commands: dict[str, Command] = CaseInsensitiveDict() @@ -615,7 +622,7 @@ class Falyx: hidden: bool = False, aliases: list[str] | None = None, help_text: str = "", - help_epilogue: str = "", + help_epilog: str = "", style: str = OneColors.WHITE, confirm: bool = False, confirm_message: str = "Are you sure?", @@ -664,7 +671,7 @@ class Falyx: hidden=hidden, aliases=aliases if aliases else [], help_text=help_text, - help_epilogue=help_epilogue, + help_epilog=help_epilog, style=style, confirm=confirm, confirm_message=confirm_message, @@ -1088,7 +1095,7 @@ class Falyx: sys.exit(0) if self.cli_args.command == "version" or self.cli_args.version: - self.console.print(f"[{OneColors.BLUE_b}]Falyx CLI v{__version__}[/]") + self.console.print(f"[{self.version_style}]{self.program} v{__version__}[/]") sys.exit(0) if self.cli_args.command == "preview": diff --git a/falyx/parsers/argparse.py b/falyx/parsers/argparse.py index 7e1e7fb..0c1a581 100644 --- a/falyx/parsers/argparse.py +++ b/falyx/parsers/argparse.py @@ -155,7 +155,7 @@ class CommandArgumentParser: command_description: str = "", command_style: str = "bold", help_text: str = "", - help_epilogue: str = "", + help_epilog: str = "", aliases: list[str] | None = None, ) -> None: """Initialize the CommandArgumentParser.""" @@ -164,7 +164,7 @@ class CommandArgumentParser: self.command_description: str = command_description self.command_style: str = command_style self.help_text: str = help_text - self.help_epilogue: str = help_epilogue + self.help_epilog: str = help_epilog self.aliases: list[str] = aliases or [] self._arguments: list[Argument] = [] self._positional: dict[str, Argument] = {} @@ -917,9 +917,9 @@ class CommandArgumentParser: arg_line.append(help_text) self.console.print(arg_line) - # Epilogue - if self.help_epilogue: - self.console.print("\n" + self.help_epilogue, style="dim") + # Epilog + if self.help_epilog: + self.console.print("\n" + self.help_epilog, style="dim") def __eq__(self, other: object) -> bool: if not isinstance(other, CommandArgumentParser): diff --git a/falyx/version.py b/falyx/version.py index 0ca817c..3d22c21 100644 --- a/falyx/version.py +++ b/falyx/version.py @@ -1 +1 @@ -__version__ = "0.1.45" +__version__ = "0.1.46" diff --git a/pyproject.toml b/pyproject.toml index 4e4ef37..7a58206 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "falyx" -version = "0.1.45" +version = "0.1.46" description = "Reliable and introspectable async CLI action framework." authors = ["Roland Thomas Jr "] license = "MIT"