MCPcopy Create free account
hub / github.com/Ishabdullah/Codey-v2 / run_positional

Function run_positional

core/peer_shell.py:286–326  ·  view source on GitHub ↗

Run a multi-word CLI command where the prompt is a positional argument. e.g. gh copilot suggest "write a function that reverses a string" The cmd string is split into argv parts and the prompt is appended as the final argument. Streams output live and captures it for Codey.

(cli_name: str, cmd: str, prompt_text: str)

Source from the content-addressed store, hash-verified

284
285
286def run_positional(cli_name: str, cmd: str, prompt_text: str) -> str:
287 """
288 Run a multi-word CLI command where the prompt is a positional argument.
289 e.g. gh copilot suggest "write a function that reverses a string"
290
291 The cmd string is split into argv parts and the prompt is appended as the
292 final argument. Streams output live and captures it for Codey.
293 """
294 import subprocess
295 width = _terminal_width()
296 border = "─" * width
297
298 argv = cmd.split() + [prompt_text]
299 print(f"\n{_CYAN}{_header(cli_name.upper() + ' CLI (direct)', width)}{_RESET}")
300 info(f"Asking {cli_name}: {prompt_text[:100]}{'…' if len(prompt_text) > 100 else ''}")
301 print(f"{_DIM}{border}{_RESET}\n")
302
303 captured = []
304 try:
305 proc = subprocess.Popen(
306 argv,
307 stdout=subprocess.PIPE,
308 stderr=subprocess.STDOUT,
309 text=True,
310 bufsize=1,
311 env={**os.environ, "CI": "true", "NO_COLOR": "1"},
312 )
313 for line in proc.stdout:
314 sys.stdout.write(line)
315 sys.stdout.flush()
316 captured.append(line)
317 proc.wait()
318 except FileNotFoundError:
319 print(f"{_RED}[peer_shell] Command not found: {argv[0]}{_RESET}")
320 except Exception as e:
321 print(f"{_RED}[peer_shell] Error: {e}{_RESET}")
322
323 print(f"\n{_DIM}{border}{_RESET}")
324 print(f"{_CYAN}{_header(cli_name.upper() + ' DONE', width)}{_RESET}\n")
325 info(f"Back in Codey — reading {cli_name} output…")
326 return "".join(captured)
327
328
329def run_direct(cli_name: str, cmd: str, prompt_text: str = "") -> str:

Callers

nothing calls this directly

Calls 6

infoFunction · 0.90
_terminal_widthFunction · 0.85
_headerFunction · 0.85
flushMethod · 0.80
appendMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected