Ask to add /run output to the chat

This commit is contained in:
Paul Gauthier 2023-05-18 10:13:50 -07:00
parent 0ade98dfff
commit a525a1b543
2 changed files with 26 additions and 3 deletions

View file

@ -13,7 +13,7 @@ class Commands:
self.coder = coder self.coder = coder
def is_command(self, inp): def is_command(self, inp):
if inp[0] == '/': if inp[0] == "/":
return True return True
def help(self): def help(self):
@ -230,12 +230,25 @@ class Commands:
"Run the supplied command in a subprocess and combine stdout and stderr into a single string" "Run the supplied command in a subprocess and combine stdout and stderr into a single string"
try: try:
parsed_args = shlex.split(args) parsed_args = shlex.split(args)
result = subprocess.run(parsed_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) result = subprocess.run(
parsed_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True
)
combined_output = result.stdout combined_output = result.stdout
print(combined_output)
except Exception as e: except Exception as e:
self.io.tool_error(f"Error running command: {e}") self.io.tool_error(f"Error running command: {e}")
print(combined_output)
ok = Confirm.ask("Add the output to the chat?", default="y")
if not ok:
return
msg = prompts.run_output.format(
command=args,
output=combined_output,
)
return msg
def cmd_ls(self, args): def cmd_ls(self, args):
"List all known files and those included in the chat session" "List all known files and those included in the chat session"

View file

@ -105,3 +105,13 @@ undo_command_reply = (
) )
added_files = "Please note that I shared content of these additional files: {fnames}" added_files = "Please note that I shared content of these additional files: {fnames}"
run_output = """I ran this command:
{command}
Which produced this output:
{output}
"""