-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@tui(help=, command=) parameters #27
Conversation
Thanks @simonw! I won't be able to review this until next week now but as a note and reminder for myself - I think there's a hardcoded check somewhere that looks like |
Good catch! Found that here: trogon/trogon/widgets/command_tree.py Line 34 in 2059c51
|
I tried to fix that and it ended up getting a bit tangled. Here's a diff that does NOT solve the problem, but does illustrate how many different layers were involved: diff --git a/trogon/trogon.py b/trogon/trogon.py
index bd33718..b872cd7 100644
--- a/trogon/trogon.py
+++ b/trogon/trogon.py
@@ -62,6 +62,7 @@ class CommandBuilder(Screen):
name: str | None = None,
id: str | None = None,
classes: str | None = None,
+ command_name: str = "tui",
):
super().__init__(name, id, classes)
self.command_data = None
@@ -69,6 +70,7 @@ class CommandBuilder(Screen):
self.is_grouped_cli = isinstance(cli, click.Group)
self.command_schemas = introspect_click_app(cli)
self.click_app_name = click_app_name
+ self.command_name = command_name
try:
self.version = metadata.version(self.click_app_name)
@@ -78,7 +80,9 @@ class CommandBuilder(Screen):
self.highlighter = ReprHighlighter()
def compose(self) -> ComposeResult:
- tree = CommandTree("Commands", self.command_schemas)
+ tree = CommandTree(
+ "Commands", self.command_schemas, command_name=self.command_name
+ )
title_parts = [Text(self.click_app_name, style="b")]
if self.version:
@@ -218,6 +222,7 @@ class Trogon(App):
cli: click.Group,
app_name: str = None,
click_context: click.Context = None,
+ command_name: str = "tui",
) -> None:
super().__init__()
self.cli = cli
@@ -228,9 +233,12 @@ class Trogon(App):
self.app_name = detect_run_string()
else:
self.app_name = app_name
+ self.command_name = command_name
def on_mount(self):
- self.push_screen(CommandBuilder(self.cli, self.app_name))
+ self.push_screen(
+ CommandBuilder(self.cli, self.app_name, command_name=self.command_name)
+ )
@on(Button.Pressed, "#home-exec-button")
def on_button_pressed(self):
diff --git a/trogon/widgets/command_tree.py b/trogon/widgets/command_tree.py
index ec05278..699b594 100644
--- a/trogon/widgets/command_tree.py
+++ b/trogon/widgets/command_tree.py
@@ -11,12 +11,18 @@ from trogon.introspect import CommandSchema, CommandName
class CommandTree(Tree[CommandSchema]):
COMPONENT_CLASSES = {"group"}
- def __init__(self, label: TextType, cli_metadata: dict[CommandName, CommandSchema]):
+ def __init__(
+ self,
+ label: TextType,
+ cli_metadata: dict[CommandName, CommandSchema],
+ command_name: str = "tui",
+ ):
super().__init__(label)
self.show_root = False
self.guide_depth = 2
self.show_guides = False
self.cli_metadata = cli_metadata
+ self.command_name = command_name
def render_label(
self, node: TreeNode[TreeDataType], base_style: Style, style: Style
@@ -31,7 +37,7 @@ class CommandTree(Tree[CommandSchema]):
) -> TreeNode:
data = {key: data[key] for key in sorted(data)}
for cmd_name, cmd_data in data.items():
- if cmd_name == "tui":
+ if cmd_name == self.command_name:
continue
if cmd_data.subcommands:
label = Text(cmd_name) I'm not sure what I missed here - the command with custom name still shows up in the tree view when I run the interactive TUI, when it should be being skipped. |
@simonw It looks like you just forgot to pass the value into |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thank you!
Refs: