MCPcopy Create free account
hub / github.com/CodeGraphContext/CodeGraphContext / run_command

Function run_command

src/codegraphcontext/cli/setup_wizard.py:532–565  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 6

_has_brewFunction · 0.85
_brew_install_neo4jFunction · 0.85
_brew_startFunction · 0.85
_set_initial_passwordFunction · 0.85
setup_dockerFunction · 0.85
setup_local_binaryFunction · 0.85

Calls 2

printMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected