machineconfig 5.65__py3-none-any.whl → 5.67__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of machineconfig might be problematic. Click here for more details.

@@ -2,896 +2,7 @@
2
2
  TUI for navigating through machineconfig command structure using Textual.
3
3
  """
4
4
 
5
- import re
6
- import subprocess
7
- from typing import Optional
8
- from dataclasses import dataclass
9
- from textual.app import App, ComposeResult
10
- from textual.containers import Horizontal, VerticalScroll
11
- from textual.widgets import Header, Footer, Tree, Static, Input, Label, Button
12
- from textual.binding import Binding
13
- from textual.screen import ModalScreen
14
- from rich.panel import Panel
15
- from rich.text import Text
16
-
17
-
18
- @dataclass
19
- class CommandInfo:
20
- """Information about a CLI command."""
21
- name: str
22
- description: str
23
- command: str
24
- parent: Optional[str] = None
25
- is_group: bool = False
26
- help_text: str = ""
27
- module_path: str = ""
28
-
29
-
30
- @dataclass
31
- class ArgumentInfo:
32
- """Information about a command argument."""
33
- name: str
34
- is_required: bool
35
- is_flag: bool
36
- placeholder: str = ""
37
- description: str = ""
38
-
39
-
40
- class CommandBuilderScreen(ModalScreen[str]):
41
- """Modal screen for building command with arguments."""
42
-
43
- def __init__(self, command_info: CommandInfo) -> None:
44
- super().__init__()
45
- self.command_info = command_info
46
- self.arguments = self._parse_arguments()
47
- self.input_widgets: dict[str, Input] = {}
48
-
49
- def _parse_arguments(self) -> list[ArgumentInfo]:
50
- """Parse arguments from help_text."""
51
- args: list[ArgumentInfo] = []
52
- seen_names: set[str] = set()
53
-
54
- if not self.command_info.help_text:
55
- return args
56
-
57
- help_text = self.command_info.help_text
58
-
59
- optional_pattern = re.compile(r'--(\w+(?:-\w+)*)\s+<([^>]+)>')
60
- for match in optional_pattern.finditer(help_text):
61
- arg_name = match.group(1)
62
- placeholder = match.group(2)
63
- if arg_name not in seen_names:
64
- args.append(ArgumentInfo(name=arg_name, is_required=False, is_flag=False, placeholder=placeholder))
65
- seen_names.add(arg_name)
66
-
67
- flag_pattern = re.compile(r'--(\w+(?:-\w+)*)(?:\s|$)')
68
- for match in flag_pattern.finditer(help_text):
69
- arg_name = match.group(1)
70
- if arg_name not in seen_names:
71
- args.append(ArgumentInfo(name=arg_name, is_required=False, is_flag=True))
72
- seen_names.add(arg_name)
73
-
74
- positional_pattern = re.compile(r'<(\w+)>(?!\s*>)')
75
- for match in positional_pattern.finditer(help_text):
76
- arg_name = match.group(1)
77
- if arg_name not in seen_names and not re.search(rf'--\w+\s+<{arg_name}>', help_text):
78
- args.append(ArgumentInfo(name=arg_name, is_required=True, is_flag=False, placeholder=arg_name))
79
- seen_names.add(arg_name)
80
-
81
- return args
82
-
83
- def compose(self) -> ComposeResult:
84
- """Compose the modal screen."""
85
- with VerticalScroll():
86
- yield Static(f"[bold cyan]Build Command: {self.command_info.command}[/bold cyan]\n", classes="title")
87
-
88
- if not self.arguments:
89
- yield Static("[yellow]No arguments needed for this command[/yellow]\n")
90
- else:
91
- for arg in self.arguments:
92
- if arg.is_flag:
93
- label_text = f"--{arg.name} (flag, leave empty to skip)"
94
- yield Label(label_text)
95
- input_widget = Input(placeholder="yes/no or leave empty", id=f"arg_{arg.name}")
96
- else:
97
- required_marker = "[red]*[/red]" if arg.is_required else "[dim](optional)[/dim]"
98
- label_text = f"--{arg.name} {required_marker}"
99
- yield Label(label_text)
100
- input_widget = Input(placeholder=arg.placeholder or arg.name, id=f"arg_{arg.name}")
101
-
102
- self.input_widgets[arg.name] = input_widget
103
- yield input_widget
104
-
105
- with Horizontal(classes="buttons"):
106
- yield Button("Execute", variant="primary", id="execute")
107
- yield Button("Copy", variant="success", id="copy")
108
- yield Button("Cancel", variant="error", id="cancel")
109
-
110
- def on_button_pressed(self, event: Button.Pressed) -> None:
111
- """Handle button presses."""
112
- if event.button.id == "cancel":
113
- self.dismiss("")
114
- return
115
-
116
- built_command = self._build_command()
117
-
118
- if event.button.id == "execute":
119
- self.dismiss(f"EXECUTE:{built_command}")
120
- elif event.button.id == "copy":
121
- self.dismiss(f"COPY:{built_command}")
122
-
123
- def _build_command(self) -> str:
124
- """Build the complete command with arguments."""
125
- parts = [self.command_info.command]
126
-
127
- for arg in self.arguments:
128
- input_widget = self.input_widgets.get(arg.name)
129
- if input_widget:
130
- value = input_widget.value.strip()
131
- if value:
132
- if arg.is_flag:
133
- if value.lower() in ('yes', 'y', 'true', '1'):
134
- parts.append(f"--{arg.name}")
135
- else:
136
- parts.append(f"--{arg.name} {value}")
137
-
138
- return " ".join(parts)
139
-
140
-
141
- class CommandTree(Tree[CommandInfo]):
142
- """Tree widget for displaying command hierarchy."""
143
-
144
- def on_mount(self) -> None:
145
- """Build the command tree when mounted."""
146
- self.show_root = False
147
- self.guide_depth = 2
148
- self._build_command_tree()
149
-
150
- def _build_command_tree(self) -> None:
151
- """Build the hierarchical command structure."""
152
-
153
- # Main entry points
154
- devops_node = self.root.add("🛠️ devops - DevOps operations", data=CommandInfo(
155
- name="devops",
156
- description="DevOps operations",
157
- command="devops",
158
- is_group=True,
159
- module_path="machineconfig.scripts.python.devops"
160
- ))
161
-
162
- # devops subcommands
163
- devops_node.add("📦 install - Install essential packages", data=CommandInfo(
164
- name="install",
165
- description="Install essential packages",
166
- command="devops install",
167
- parent="devops",
168
- help_text="devops install --which <packages> --group <group> --interactive"
169
- ))
170
-
171
- repos_node = devops_node.add("📁 repos - Manage git repositories", data=CommandInfo(
172
- name="repos",
173
- description="Manage git repositories",
174
- command="devops repos",
175
- parent="devops",
176
- is_group=True,
177
- module_path="machineconfig.scripts.python.devops_helpers.cli_repos"
178
- ))
179
-
180
- # repos subcommands
181
- repos_node.add("🚀 push - Push changes across repositories", data=CommandInfo(
182
- name="push",
183
- description="Push changes across repositories",
184
- command="devops repos push",
185
- parent="repos",
186
- help_text="devops repos push --directory <dir> --recursive --no-sync"
187
- ))
188
-
189
- repos_node.add("⬇️ pull - Pull changes across repositories", data=CommandInfo(
190
- name="pull",
191
- description="Pull changes across repositories",
192
- command="devops repos pull",
193
- parent="repos",
194
- help_text="devops repos pull --directory <dir> --recursive --no-sync"
195
- ))
196
-
197
- repos_node.add("💾 commit - Commit changes across repositories", data=CommandInfo(
198
- name="commit",
199
- description="Commit changes across repositories",
200
- command="devops repos commit",
201
- parent="repos",
202
- help_text="devops repos commit --directory <dir> --recursive --no-sync"
203
- ))
204
-
205
- repos_node.add("🔄 sync - Sync changes across repositories", data=CommandInfo(
206
- name="sync",
207
- description="Pull, commit, and push changes across repositories",
208
- command="devops repos sync",
209
- parent="repos",
210
- help_text="devops repos sync --directory <dir> --recursive --no-sync"
211
- ))
212
-
213
- mirror_node = repos_node.add("🔄 mirror - Manage repository specifications", data=CommandInfo(
214
- name="mirror",
215
- description="Manage repository specifications and syncing",
216
- command="devops repos mirror",
217
- parent="repos",
218
- is_group=True
219
- ))
220
-
221
- mirror_node.add("📝 capture - Record repositories into repos.json", data=CommandInfo(
222
- name="capture",
223
- description="Record repositories into a repos.json specification",
224
- command="devops repos mirror capture",
225
- parent="mirror",
226
- help_text="devops repos mirror capture --directory <dir> --cloud <cloud>"
227
- ))
228
-
229
- mirror_node.add("📥 clone - Clone repositories from repos.json", data=CommandInfo(
230
- name="clone",
231
- description="Clone repositories described by repos.json",
232
- command="devops repos mirror clone",
233
- parent="mirror",
234
- help_text="devops repos mirror clone --directory <dir> --cloud <cloud>"
235
- ))
236
-
237
- mirror_node.add("🔀 checkout-to-commit - Check out specific commits", data=CommandInfo(
238
- name="checkout-to-commit",
239
- description="Check out specific commits listed in specification",
240
- command="devops repos mirror checkout-to-commit",
241
- parent="mirror",
242
- help_text="devops repos mirror checkout-to-commit --directory <dir> --cloud <cloud>"
243
- ))
244
-
245
- mirror_node.add("🔀 checkout-to-branch - Check out to main branch", data=CommandInfo(
246
- name="checkout-to-branch",
247
- description="Check out to the main branch defined in specification",
248
- command="devops repos mirror checkout-to-branch",
249
- parent="mirror",
250
- help_text="devops repos mirror checkout-to-branch --directory <dir> --cloud <cloud>"
251
- ))
252
-
253
- repos_node.add("🔍 analyze - Analyze repositories", data=CommandInfo(
254
- name="analyze",
255
- description="Analyze repositories in directory",
256
- command="devops repos analyze",
257
- parent="repos",
258
- help_text="devops repos analyze --directory <dir>"
259
- ))
260
-
261
- repos_node.add("🔐 secure - Securely sync git repository", data=CommandInfo(
262
- name="secure",
263
- description="Securely sync git repository to/from cloud with encryption",
264
- command="devops repos secure",
265
- parent="repos",
266
- help_text="devops repos secure <path> --cloud <cloud> --encrypt --decrypt"
267
- ))
268
-
269
- repos_node.add("🎬 viz - Visualize repository activity", data=CommandInfo(
270
- name="viz",
271
- description="Visualize repository activity using Gource",
272
- command="devops repos viz",
273
- parent="repos",
274
- help_text="devops repos viz --repo <path> --output <file> --resolution <res> --seconds-per-day <spd>"
275
- ))
276
-
277
- repos_node.add("🧹 cleanup - Clean repository directories", data=CommandInfo(
278
- name="cleanup",
279
- description="Clean repository directories from cache files",
280
- command="devops repos cleanup",
281
- parent="repos",
282
- help_text="devops repos cleanup --repo <path> --recursive"
283
- ))
284
-
285
- # config subcommands
286
- config_node = devops_node.add("⚙️ config - Configuration management", data=CommandInfo(
287
- name="config",
288
- description="Configuration subcommands",
289
- command="devops config",
290
- parent="devops",
291
- is_group=True
292
- ))
293
-
294
- config_node.add("🔗 private - Manage private configuration files", data=CommandInfo(
295
- name="private",
296
- description="Manage private configuration files",
297
- command="devops config private",
298
- parent="config",
299
- help_text="devops config private --method <symlink|copy> --on-conflict <action> --which <items> --interactive"
300
- ))
301
-
302
- config_node.add("🔗 public - Manage public configuration files", data=CommandInfo(
303
- name="public",
304
- description="Manage public configuration files",
305
- command="devops config public",
306
- parent="config",
307
- help_text="devops config public --method <symlink|copy> --on-conflict <action> --which <items> --interactive"
308
- ))
309
-
310
- config_node.add("🔗 dotfile - Manage dotfiles", data=CommandInfo(
311
- name="dotfile",
312
- description="Manage dotfiles",
313
- command="devops config dotfile",
314
- parent="config",
315
- help_text="devops config dotfile <file> --overwrite --dest <destination>"
316
- ))
317
-
318
- config_node.add("🔗 shell - Configure shell profile", data=CommandInfo(
319
- name="shell",
320
- description="Configure your shell profile",
321
- command="devops config shell",
322
- parent="config",
323
- help_text="devops config shell <copy|reference>"
324
- ))
325
-
326
- config_node.add("🔗 pwsh_theme - Configure PowerShell theme", data=CommandInfo(
327
- name="pwsh_theme",
328
- description="Configure your PowerShell theme",
329
- command="devops config pwsh_theme",
330
- parent="config",
331
- help_text="devops config pwsh_theme"
332
- ))
333
-
334
- # data subcommands
335
- data_node = devops_node.add("💾 data - Data operations", data=CommandInfo(
336
- name="data",
337
- description="Data subcommands",
338
- command="devops data",
339
- parent="devops",
340
- is_group=True
341
- ))
342
-
343
- data_node.add("💾 backup - Backup data", data=CommandInfo(
344
- name="backup",
345
- description="Backup data",
346
- command="devops data backup",
347
- parent="data",
348
- help_text="devops data backup"
349
- ))
350
-
351
- data_node.add("📥 retrieve - Retrieve data", data=CommandInfo(
352
- name="retrieve",
353
- description="Retrieve data from backup",
354
- command="devops data retrieve",
355
- parent="data",
356
- help_text="devops data retrieve"
357
- ))
358
-
359
- # network subcommands
360
- network_node = devops_node.add("🔐 network - Network operations", data=CommandInfo(
361
- name="network",
362
- description="Network subcommands",
363
- command="devops network",
364
- parent="devops",
365
- is_group=True
366
- ))
367
-
368
- network_node.add("📡 share-terminal - Share terminal via web", data=CommandInfo(
369
- name="share-terminal",
370
- description="Share terminal via web browser",
371
- command="devops network share-terminal",
372
- parent="network",
373
- help_text="devops network share-terminal"
374
- ))
375
-
376
- network_node.add("� install_ssh_server - Install SSH server", data=CommandInfo(
377
- name="install_ssh_server",
378
- description="Install SSH server",
379
- command="devops network install_ssh_server",
380
- parent="network",
381
- help_text="devops network install_ssh_server"
382
- ))
383
-
384
- network_node.add("� add_ssh_key - Add SSH public key", data=CommandInfo(
385
- name="add_ssh_key",
386
- description="Add SSH public key to this machine",
387
- command="devops network add_ssh_key",
388
- parent="network",
389
- help_text="devops network add_ssh_key --path <file> --choose --value --github <username>"
390
- ))
391
-
392
- network_node.add("�️ add_ssh_identity - Add SSH identity", data=CommandInfo(
393
- name="add_ssh_identity",
394
- description="Add SSH identity (private key) to this machine",
395
- command="devops network add_ssh_identity",
396
- parent="network",
397
- help_text="devops network add_ssh_identity"
398
- ))
399
-
400
- # self subcommands
401
- self_node = devops_node.add("🔄 self - SELF operations", data=CommandInfo(
402
- name="self",
403
- description="SELF operations subcommands",
404
- command="devops self",
405
- parent="devops",
406
- is_group=True
407
- ))
408
-
409
- self_node.add("🔄 update - Update essential repos", data=CommandInfo(
410
- name="update",
411
- description="Update essential repos",
412
- command="devops self update",
413
- parent="self",
414
- help_text="devops self update"
415
- ))
416
-
417
- self_node.add("🤖 interactive - Interactive configuration", data=CommandInfo(
418
- name="interactive",
419
- description="Interactive configuration of machine",
420
- command="devops self interactive",
421
- parent="self",
422
- help_text="devops self interactive"
423
- ))
424
-
425
- self_node.add("📊 status - Machine status", data=CommandInfo(
426
- name="status",
427
- description="Status of machine, shell profile, apps, symlinks, dotfiles, etc.",
428
- command="devops self status",
429
- parent="self",
430
- help_text="devops self status"
431
- ))
432
-
433
- self_node.add("📋 clone - Clone machineconfig", data=CommandInfo(
434
- name="clone",
435
- description="Clone machineconfig locally and incorporate to shell profile",
436
- command="devops self clone",
437
- parent="self",
438
- help_text="devops self clone"
439
- ))
440
-
441
- self_node.add("📚 navigate - Navigate command structure", data=CommandInfo(
442
- name="navigate",
443
- description="Navigate command structure with TUI",
444
- command="devops self navigate",
445
- parent="self",
446
- help_text="devops self navigate"
447
- ))
448
-
449
- # fire command
450
- self.root.add("🔥 fire - Fire jobs execution", data=CommandInfo(
451
- name="fire",
452
- description="Execute Python scripts with Fire",
453
- command="fire",
454
- is_group=False,
455
- module_path="machineconfig.scripts.python.fire_jobs",
456
- help_text="fire <path> [function] --ve <env> --interactive --jupyter --streamlit --debug --loop --remote --zellij_tab <name>"
457
- ))
458
-
459
- # agents command
460
- agents_node = self.root.add("🤖 agents - AI Agents management", data=CommandInfo(
461
- name="agents",
462
- description="AI Agents management subcommands",
463
- command="agents",
464
- is_group=True,
465
- module_path="machineconfig.scripts.python.agents"
466
- ))
467
-
468
- agents_node.add("✨ create - Create AI agent", data=CommandInfo(
469
- name="create",
470
- description="Create a new AI agent",
471
- command="agents create",
472
- parent="agents",
473
- help_text="agents create --context-path <file> --keyword-search <term> --filename-pattern <pattern> --agent <type> --machine <target> --model <model> --provider <provider> --prompt <text> --prompt-path <file> --job-name <name> --tasks-per-prompt <num> --separate-prompt-from-context --output-path <file> --agents-dir <dir>"
474
- ))
475
-
476
- agents_node.add("📦 collect - Collect agent data", data=CommandInfo(
477
- name="collect",
478
- description="Collect agent data",
479
- command="agents collect",
480
- parent="agents",
481
- help_text="agents collect --agent-dir <dir> --output-path <file> --separator <sep>"
482
- ))
483
-
484
- agents_node.add("📝 make-template - Create agent template", data=CommandInfo(
485
- name="make-template",
486
- description="Create a template for fire agents",
487
- command="agents make-template",
488
- parent="agents",
489
- help_text="agents make-template"
490
- ))
491
-
492
- agents_node.add("⚙️ make-config - Initialize AI configurations", data=CommandInfo(
493
- name="make-config",
494
- description="Initialize AI configurations in the current repository",
495
- command="agents make-config",
496
- parent="agents",
497
- help_text="agents make-config"
498
- ))
499
-
500
- agents_node.add("📝 make-todo - Generate todo markdown", data=CommandInfo(
501
- name="make-todo",
502
- description="Generate a markdown file listing all Python files in the repo",
503
- command="agents make-todo",
504
- parent="agents",
505
- help_text="agents make-todo"
506
- ))
507
-
508
- # sessions command
509
- sessions_node = self.root.add("🖥️ sessions - Session layouts management", data=CommandInfo(
510
- name="sessions",
511
- description="Layouts management subcommands",
512
- command="sessions",
513
- is_group=True,
514
- module_path="machineconfig.scripts.python.sessions"
515
- ))
516
-
517
- sessions_node.add("✨ create-from-function - Create layout from function", data=CommandInfo(
518
- name="create-from-function",
519
- description="Create layout from function",
520
- command="sessions create-from-function",
521
- parent="sessions",
522
- help_text="sessions create-from-function"
523
- ))
524
-
525
- sessions_node.add("▶️ run - Run session layout", data=CommandInfo(
526
- name="run",
527
- description="Run session layout",
528
- command="sessions run",
529
- parent="sessions",
530
- help_text="sessions run --layout-path <file> --max-tabs <num> --max-layouts <num> --sleep-inbetween <sec> --monitor --parallel --kill-upon-completion --choose <names> --choose-interactively"
531
- ))
532
-
533
- sessions_node.add("⚖️ balance-load - Balance load", data=CommandInfo(
534
- name="balance-load",
535
- description="Balance load across sessions",
536
- command="sessions balance-load",
537
- parent="sessions",
538
- help_text="sessions balance-load --layout-path <file> --max-thresh <num> --thresh-type <number|weight> --breaking-method <moreLayouts|combineTabs> --output-path <file>"
539
- ))
540
-
541
- # cloud command
542
- cloud_node = self.root.add("☁️ cloud - Cloud storage operations", data=CommandInfo(
543
- name="cloud",
544
- description="Cloud storage operations",
545
- command="cloud",
546
- is_group=True,
547
- module_path="machineconfig.scripts.python.cloud"
548
- ))
549
-
550
- cloud_node.add("🔄 sync - Synchronize with cloud", data=CommandInfo(
551
- name="sync",
552
- description="Synchronize files/folders between local and cloud storage",
553
- command="cloud sync",
554
- parent="cloud",
555
- help_text="cloud sync <source> <target> --cloud <provider> --recursive --exclude <patterns>"
556
- ))
557
-
558
- cloud_node.add("📤 copy - Copy to/from cloud", data=CommandInfo(
559
- name="copy",
560
- description="Copy files/folders to/from cloud storage",
561
- command="cloud copy",
562
- parent="cloud",
563
- help_text="cloud copy <source> <target> --cloud <provider> --recursive --exclude <patterns>"
564
- ))
565
-
566
- cloud_node.add("🔗 mount - Mount cloud storage", data=CommandInfo(
567
- name="mount",
568
- description="Mount cloud storage as local drive",
569
- command="cloud mount",
570
- parent="cloud",
571
- help_text="cloud mount <remote> <mount_point> --cloud <provider> --daemon --allow-other"
572
- ))
573
-
574
- # croshell command
575
- self.root.add("� croshell - Interactive shell", data=CommandInfo(
576
- name="croshell",
577
- description="Interactive shell with various options",
578
- command="croshell",
579
- is_group=False,
580
- module_path="machineconfig.scripts.python.croshell",
581
- help_text="croshell --python --fzf --ve <env> --profile <profile> --read <file> --jupyter --streamlit --visidata"
582
- ))
583
-
584
- # ftpx command
585
- self.root.add("📡 ftpx - File transfer", data=CommandInfo(
586
- name="ftpx",
587
- description="File transfer between machines",
588
- command="ftpx",
589
- is_group=False,
590
- module_path="machineconfig.scripts.python.ftpx",
591
- help_text="ftpx <source> <target> --recursive --zipFirst --cloud"
592
- ))
593
-
594
- # kill_process command
595
- self.root.add("💀 kill_process - Kill processes", data=CommandInfo(
596
- name="kill_process",
597
- description="Kill running processes",
598
- command="kill_process",
599
- is_group=False,
600
- module_path="machineconfig.utils.procs",
601
- help_text="kill_process"
602
- ))
603
-
604
-
605
- class CommandDetail(Static):
606
- """Widget for displaying command details."""
607
-
608
- def __init__(self, *, id: str) -> None: # type: ignore
609
- super().__init__(id=id)
610
- self.command_info: Optional[CommandInfo] = None
611
-
612
- def update_command(self, command_info: Optional[CommandInfo]) -> None:
613
- """Update displayed command information."""
614
- self.command_info = command_info
615
- if command_info is None:
616
- self.update("Select a command to view details")
617
- return
618
-
619
- content = Text()
620
- content.append(f"{'🗂️ Group' if command_info.is_group else '⚡ Command'}: ", style="bold cyan")
621
- content.append(f"{command_info.name}\n\n", style="bold yellow")
622
-
623
- content.append("Description: ", style="bold green")
624
- content.append(f"{command_info.description}\n\n", style="white")
625
-
626
- content.append("Command: ", style="bold blue")
627
- content.append(f"{command_info.command}\n\n", style="bold white")
628
-
629
- if command_info.help_text:
630
- content.append("Usage: ", style="bold magenta")
631
- content.append(f"{command_info.help_text}\n\n", style="white")
632
-
633
- if command_info.module_path:
634
- content.append("Module: ", style="bold red")
635
- content.append(f"{command_info.module_path}\n", style="white")
636
-
637
- self.update(Panel(content, title=f"[bold]{command_info.name}[/bold]", border_style="blue"))
638
-
639
-
640
- class SearchBar(Horizontal):
641
- """Search bar widget."""
642
-
643
- def compose(self) -> ComposeResult:
644
- yield Label("🔍 Search: ", classes="search-label")
645
- yield Input(placeholder="Type to search commands...", id="search-input")
646
-
647
-
648
- class CommandNavigatorApp(App[None]):
649
- """TUI application for navigating machineconfig commands."""
650
-
651
- CSS = """
652
- Screen {
653
- layout: grid;
654
- grid-size: 2 3;
655
- grid-rows: auto 1fr auto;
656
- }
657
-
658
- Header {
659
- column-span: 2;
660
- background: $boost;
661
- color: $text;
662
- }
663
-
664
- #search-bar {
665
- column-span: 2;
666
- padding: 1;
667
- background: $surface;
668
- height: auto;
669
- }
670
-
671
- .search-label {
672
- width: auto;
673
- padding-right: 1;
674
- }
675
-
676
- #search-input {
677
- width: 1fr;
678
- }
679
-
680
- #command-tree {
681
- row-span: 1;
682
- border: solid $primary;
683
- padding: 1;
684
- }
685
-
686
- #command-detail {
687
- row-span: 1;
688
- border: solid $primary;
689
- padding: 1;
690
- }
691
-
692
- Footer {
693
- column-span: 2;
694
- background: $boost;
695
- }
696
-
697
- Button {
698
- margin: 1;
699
- }
700
-
701
- CommandBuilderScreen {
702
- align: center middle;
703
- }
704
-
705
- CommandBuilderScreen > VerticalScroll {
706
- width: 80;
707
- height: auto;
708
- max-height: 90%;
709
- background: $surface;
710
- border: thick $primary;
711
- padding: 2;
712
- }
713
-
714
- CommandBuilderScreen .title {
715
- margin-bottom: 1;
716
- }
717
-
718
- CommandBuilderScreen Label {
719
- margin-top: 1;
720
- margin-bottom: 0;
721
- }
722
-
723
- CommandBuilderScreen Input {
724
- margin-bottom: 1;
725
- }
726
-
727
- CommandBuilderScreen .buttons {
728
- margin-top: 2;
729
- height: auto;
730
- align: center middle;
731
- }
732
- """
733
-
734
- BINDINGS = [
735
- Binding("q", "quit", "Quit", priority=True),
736
- Binding("c", "copy_command", "Copy Command"),
737
- Binding("/", "focus_search", "Search"),
738
- Binding("?", "help", "Help"),
739
- Binding("r", "run_command", "Run Command"),
740
- Binding("b", "build_command", "Build Command"),
741
- ]
742
-
743
- def compose(self) -> ComposeResult:
744
- """Create child widgets for the app."""
745
- yield Header(show_clock=True)
746
- yield SearchBar(id="search-bar")
747
- yield CommandTree("📚 machineconfig Commands", id="command-tree")
748
- yield CommandDetail(id="command-detail")
749
- yield Footer()
750
-
751
- def on_mount(self) -> None:
752
- """Actions when app is mounted."""
753
- self.title = "machineconfig Command Navigator"
754
- self.sub_title = "Navigate and explore all available commands"
755
- tree = self.query_one(CommandTree)
756
- tree.focus()
757
-
758
- def on_tree_node_selected(self, event: Tree.NodeSelected[CommandInfo]) -> None:
759
- """Handle tree node selection."""
760
- command_info = event.node.data
761
- detail_widget = self.query_one("#command-detail", CommandDetail)
762
- detail_widget.update_command(command_info)
763
-
764
- def on_input_changed(self, event: Input.Changed) -> None:
765
- """Handle search input changes."""
766
- if event.input.id != "search-input":
767
- return
768
-
769
- search_term = event.value.lower()
770
- tree = self.query_one(CommandTree)
771
-
772
- if not search_term:
773
- # Show all nodes - expand all root children
774
- for node in tree.root.children:
775
- node.expand()
776
- return
777
-
778
- # Filter nodes based on search term
779
- def filter_tree(node): # type: ignore
780
- if node.data and not node.data.is_group:
781
- match = (search_term in node.data.name.lower() or
782
- search_term in node.data.description.lower() or
783
- search_term in node.data.command.lower())
784
- return match
785
- return False
786
-
787
- # Expand parents of matching nodes by walking through all nodes
788
- def walk_nodes(node): # type: ignore
789
- """Recursively walk through tree nodes."""
790
- yield node
791
- for child in node.children:
792
- yield from walk_nodes(child)
793
-
794
- for node in walk_nodes(tree.root):
795
- if filter_tree(node):
796
- parent = node.parent
797
- while parent and parent != tree.root:
798
- parent.expand()
799
- parent = parent.parent # type: ignore
800
-
801
- def action_copy_command(self) -> None:
802
- """Copy the selected command to clipboard."""
803
- tree = self.query_one(CommandTree)
804
- if tree.cursor_node and tree.cursor_node.data:
805
- command = tree.cursor_node.data.command
806
- try:
807
- import pyperclip # type: ignore
808
- pyperclip.copy(command)
809
- self.notify(f"Copied: {command}", severity="information")
810
- except ImportError:
811
- self.notify("Install pyperclip to enable clipboard support", severity="warning")
812
-
813
- def action_run_command(self) -> None:
814
- """Run the selected command without arguments."""
815
- tree = self.query_one(CommandTree)
816
- if tree.cursor_node and tree.cursor_node.data:
817
- command_info = tree.cursor_node.data
818
- if command_info.is_group:
819
- self.notify("Cannot run command groups directly", severity="warning")
820
- return
821
-
822
- self._execute_command(command_info.command)
823
-
824
- def action_build_command(self) -> None:
825
- """Open command builder for selected command."""
826
- tree = self.query_one(CommandTree)
827
- if tree.cursor_node and tree.cursor_node.data:
828
- command_info = tree.cursor_node.data
829
- if command_info.is_group:
830
- self.notify("Cannot build command for groups", severity="warning")
831
- return
832
-
833
- self.push_screen(CommandBuilderScreen(command_info), self._handle_builder_result)
834
-
835
- def _handle_builder_result(self, result: str | None) -> None:
836
- """Handle result from command builder."""
837
- if not result:
838
- return
839
-
840
- if result.startswith("EXECUTE:"):
841
- command = result[8:]
842
- self._execute_command(command)
843
- elif result.startswith("COPY:"):
844
- command = result[5:]
845
- self._copy_to_clipboard(command)
846
-
847
- def _execute_command(self, command: str) -> None:
848
- """Execute a shell command."""
849
- try:
850
- self.notify(f"Executing: {command}", severity="information")
851
- result = subprocess.run(command, shell=True, capture_output=True, text=True, timeout=30)
852
-
853
- if result.returncode == 0:
854
- output = result.stdout.strip()
855
- if output:
856
- self.notify(f"Success: {output[:100]}...", severity="information", timeout=5)
857
- else:
858
- self.notify("Command executed successfully", severity="information")
859
- else:
860
- error = result.stderr.strip() or "Unknown error"
861
- self.notify(f"Error: {error[:100]}...", severity="error", timeout=10)
862
- except subprocess.TimeoutExpired:
863
- self.notify("Command timed out after 30 seconds", severity="warning")
864
- except Exception as e:
865
- self.notify(f"Failed to execute: {str(e)}", severity="error")
866
-
867
- def _copy_to_clipboard(self, command: str) -> None:
868
- """Copy command to clipboard."""
869
- try:
870
- import pyperclip # type: ignore
871
- pyperclip.copy(command)
872
- self.notify(f"Copied: {command}", severity="information")
873
- except ImportError:
874
- self.notify("Install pyperclip to enable clipboard support", severity="warning")
875
-
876
- def action_focus_search(self) -> None:
877
- """Focus the search input."""
878
- search_input = self.query_one("#search-input", Input)
879
- search_input.focus()
880
-
881
- def action_help(self) -> None:
882
- """Show help information."""
883
- help_text = """
884
- Navigation:
885
- - ↑↓: Navigate tree
886
- - Enter: Expand/collapse node
887
- - /: Focus search
888
- - c: Copy command to clipboard
889
- - r: Run command directly (no args)
890
- - b: Build command with arguments
891
- - q: Quit
892
- - ?: Show this help
893
- """
894
- self.notify(help_text, severity="information", timeout=10)
5
+ from machineconfig.scripts.python.helper_navigator import CommandNavigatorApp
895
6
 
896
7
 
897
8
  if __name__ == "__main__":