Runs a command, captures its output, and handles execution. Returns the completed process object on success, None on failure.
(command, console, shell=False, check=True, input_text=None)
| 535 | return Path.cwd() |
| 536 | |
| 537 | def run_command(command, console, shell=False, check=True, input_text=None): |
| 538 | """ |
| 539 | Runs a command, captures its output, and handles execution. |
| 540 | Returns the completed process object on success, None on failure. |
| 541 | """ |
| 542 | cmd_str = command if isinstance(command, str) else ' '.join(command) |
| 543 | |
| 544 | # Mask passwords from being printed out |
| 545 | if "set-initial-password" in cmd_str: |
| 546 | import re |
| 547 | cmd_str = re.sub(r'(set-initial-password\s+)(\S+)', r'\g<1>********', cmd_str) |
| 548 | |
| 549 | console.print(f"[cyan]$ {cmd_str}[/cyan]") |
| 550 | try: |
| 551 | process = subprocess.run( |
| 552 | command, |
| 553 | shell=shell, |
| 554 | check=check, |
| 555 | capture_output=True, # Always capture to control what gets displayed |
| 556 | text=True, |
| 557 | timeout=300, |
| 558 | input=input_text |
| 559 | ) |
| 560 | return process |
| 561 | except subprocess.CalledProcessError as e: |
| 562 | console.print(f"[bold red]Error executing command:[/bold red] {cmd_str}") |
| 563 | if e.stdout: |
| 564 | console.print(f"[red]STDOUT: {e.stdout}[/red]") |
| 565 | if e.stderr: |
| 566 | console.print(f"[red]STDERR: {e.stderr}[/red]") |
| 567 | return None |
| 568 | except subprocess.TimeoutExpired: |
| 569 | console.print(f"[bold red]Command timed out:[/bold red] {cmd_str}") |
| 570 | return None |
| 571 | |
| 572 | def run_neo4j_setup_wizard(): |
| 573 | """Guides the user through setting up Neo4j database for CodeGraphContext.""" |
no test coverage detected