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()
|
await self.flx.run()
|
||||||
|
|
||||||
|
|
||||||
def parse_args() -> Namespace:
|
|
||||||
parsers: FalyxParsers = get_arg_parsers()
|
|
||||||
return parsers.parse_args()
|
|
||||||
|
|
||||||
|
|
||||||
async def main() -> None:
|
async def main() -> None:
|
||||||
"""Build and return a Falyx instance with all your commands."""
|
"""Build and return a Falyx instance with all your commands."""
|
||||||
args = parse_args()
|
|
||||||
flx = Falyx(
|
flx = Falyx(
|
||||||
title="🚀 Falyx CLI",
|
title="🚀 Falyx CLI",
|
||||||
cli_args=args,
|
|
||||||
columns=5,
|
columns=5,
|
||||||
welcome_message="Welcome to Falyx CLI!",
|
welcome_message="Welcome to Falyx CLI!",
|
||||||
exit_message="Goodbye!",
|
exit_message="Goodbye!",
|
||||||
|
|
|
@ -97,7 +97,7 @@ def main() -> Any:
|
||||||
init_project,
|
init_project,
|
||||||
aliases=["init"],
|
aliases=["init"],
|
||||||
argument_config=init_config,
|
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(
|
flx.add_command(
|
||||||
"G",
|
"G",
|
||||||
|
|
|
@ -111,7 +111,7 @@ class Command(BaseModel):
|
||||||
hidden: bool = False
|
hidden: bool = False
|
||||||
aliases: list[str] = Field(default_factory=list)
|
aliases: list[str] = Field(default_factory=list)
|
||||||
help_text: str = ""
|
help_text: str = ""
|
||||||
help_epilogue: str = ""
|
help_epilog: str = ""
|
||||||
style: str = OneColors.WHITE
|
style: str = OneColors.WHITE
|
||||||
confirm: bool = False
|
confirm: bool = False
|
||||||
confirm_message: str = "Are you sure?"
|
confirm_message: str = "Are you sure?"
|
||||||
|
@ -233,7 +233,7 @@ class Command(BaseModel):
|
||||||
command_description=self.description,
|
command_description=self.description,
|
||||||
command_style=self.style,
|
command_style=self.style,
|
||||||
help_text=self.help_text,
|
help_text=self.help_text,
|
||||||
help_epilogue=self.help_epilogue,
|
help_epilog=self.help_epilog,
|
||||||
aliases=self.aliases,
|
aliases=self.aliases,
|
||||||
)
|
)
|
||||||
for arg_def in self.get_argument_definitions():
|
for arg_def in self.get_argument_definitions():
|
||||||
|
|
|
@ -102,7 +102,7 @@ class RawCommand(BaseModel):
|
||||||
retry_policy: RetryPolicy = Field(default_factory=RetryPolicy)
|
retry_policy: RetryPolicy = Field(default_factory=RetryPolicy)
|
||||||
hidden: bool = False
|
hidden: bool = False
|
||||||
help_text: str = ""
|
help_text: str = ""
|
||||||
help_epilogue: str = ""
|
help_epilog: str = ""
|
||||||
|
|
||||||
@field_validator("retry_policy")
|
@field_validator("retry_policy")
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -88,6 +88,11 @@ class CommandValidator(Validator):
|
||||||
|
|
||||||
async def validate_async(self, document) -> None:
|
async def validate_async(self, document) -> None:
|
||||||
text = document.text
|
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)
|
is_preview, choice, _, __ = await self.falyx.get_command(text, from_validate=True)
|
||||||
if is_preview:
|
if is_preview:
|
||||||
return None
|
return None
|
||||||
|
@ -157,6 +162,7 @@ class Falyx:
|
||||||
description: str | None = "Falyx CLI - Run structured async command workflows.",
|
description: str | None = "Falyx CLI - Run structured async command workflows.",
|
||||||
epilog: str | None = None,
|
epilog: str | None = None,
|
||||||
version: str = __version__,
|
version: str = __version__,
|
||||||
|
version_style: str = OneColors.BLUE_b,
|
||||||
prompt: str | AnyFormattedText = "> ",
|
prompt: str | AnyFormattedText = "> ",
|
||||||
columns: int = 3,
|
columns: int = 3,
|
||||||
bottom_bar: BottomBar | str | Callable[[], Any] | None = None,
|
bottom_bar: BottomBar | str | Callable[[], Any] | None = None,
|
||||||
|
@ -180,6 +186,7 @@ class Falyx:
|
||||||
self.description: str | None = description
|
self.description: str | None = description
|
||||||
self.epilog: str | None = epilog
|
self.epilog: str | None = epilog
|
||||||
self.version: str = version
|
self.version: str = version
|
||||||
|
self.version_style: str = version_style
|
||||||
self.prompt: str | AnyFormattedText = prompt
|
self.prompt: str | AnyFormattedText = prompt
|
||||||
self.columns: int = columns
|
self.columns: int = columns
|
||||||
self.commands: dict[str, Command] = CaseInsensitiveDict()
|
self.commands: dict[str, Command] = CaseInsensitiveDict()
|
||||||
|
@ -615,7 +622,7 @@ class Falyx:
|
||||||
hidden: bool = False,
|
hidden: bool = False,
|
||||||
aliases: list[str] | None = None,
|
aliases: list[str] | None = None,
|
||||||
help_text: str = "",
|
help_text: str = "",
|
||||||
help_epilogue: str = "",
|
help_epilog: str = "",
|
||||||
style: str = OneColors.WHITE,
|
style: str = OneColors.WHITE,
|
||||||
confirm: bool = False,
|
confirm: bool = False,
|
||||||
confirm_message: str = "Are you sure?",
|
confirm_message: str = "Are you sure?",
|
||||||
|
@ -664,7 +671,7 @@ class Falyx:
|
||||||
hidden=hidden,
|
hidden=hidden,
|
||||||
aliases=aliases if aliases else [],
|
aliases=aliases if aliases else [],
|
||||||
help_text=help_text,
|
help_text=help_text,
|
||||||
help_epilogue=help_epilogue,
|
help_epilog=help_epilog,
|
||||||
style=style,
|
style=style,
|
||||||
confirm=confirm,
|
confirm=confirm,
|
||||||
confirm_message=confirm_message,
|
confirm_message=confirm_message,
|
||||||
|
@ -1088,7 +1095,7 @@ class Falyx:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if self.cli_args.command == "version" or self.cli_args.version:
|
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)
|
sys.exit(0)
|
||||||
|
|
||||||
if self.cli_args.command == "preview":
|
if self.cli_args.command == "preview":
|
||||||
|
|
|
@ -155,7 +155,7 @@ class CommandArgumentParser:
|
||||||
command_description: str = "",
|
command_description: str = "",
|
||||||
command_style: str = "bold",
|
command_style: str = "bold",
|
||||||
help_text: str = "",
|
help_text: str = "",
|
||||||
help_epilogue: str = "",
|
help_epilog: str = "",
|
||||||
aliases: list[str] | None = None,
|
aliases: list[str] | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the CommandArgumentParser."""
|
"""Initialize the CommandArgumentParser."""
|
||||||
|
@ -164,7 +164,7 @@ class CommandArgumentParser:
|
||||||
self.command_description: str = command_description
|
self.command_description: str = command_description
|
||||||
self.command_style: str = command_style
|
self.command_style: str = command_style
|
||||||
self.help_text: str = help_text
|
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.aliases: list[str] = aliases or []
|
||||||
self._arguments: list[Argument] = []
|
self._arguments: list[Argument] = []
|
||||||
self._positional: dict[str, Argument] = {}
|
self._positional: dict[str, Argument] = {}
|
||||||
|
@ -917,9 +917,9 @@ class CommandArgumentParser:
|
||||||
arg_line.append(help_text)
|
arg_line.append(help_text)
|
||||||
self.console.print(arg_line)
|
self.console.print(arg_line)
|
||||||
|
|
||||||
# Epilogue
|
# Epilog
|
||||||
if self.help_epilogue:
|
if self.help_epilog:
|
||||||
self.console.print("\n" + self.help_epilogue, style="dim")
|
self.console.print("\n" + self.help_epilog, style="dim")
|
||||||
|
|
||||||
def __eq__(self, other: object) -> bool:
|
def __eq__(self, other: object) -> bool:
|
||||||
if not isinstance(other, CommandArgumentParser):
|
if not isinstance(other, CommandArgumentParser):
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
__version__ = "0.1.45"
|
__version__ = "0.1.46"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "falyx"
|
name = "falyx"
|
||||||
version = "0.1.45"
|
version = "0.1.46"
|
||||||
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"
|
||||||
|
|
Loading…
Reference in New Issue