Normalize epilogue -> epilog, allow version to be modifiable, don't allow empty input in repl
This commit is contained in:
parent
1c97857cb8
commit
079bc0ee77
|
@ -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!",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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():
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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":
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -1 +1 @@
|
|||
__version__ = "0.1.45"
|
||||
__version__ = "0.1.46"
|
||||
|
|
|
@ -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 <roland@rtj.dev>"]
|
||||
license = "MIT"
|
||||
|
|
Loading…
Reference in New Issue