Skip to content

Commit

Permalink
Dry run flag\n\nPrints the script and asks the user if they should ru…
Browse files Browse the repository at this point in the history
…n it
  • Loading branch information
jakethekoenig committed Jan 30, 2024
1 parent abfbc91 commit df2e270
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions rawdog/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 9,17 @@
def rawdog(prompt: str):
output = None
error, script = llm_client.get_script(prompt)
def confirm_execution(script: str) -> bool:
print("Dry run is enabled. The script to be executed is:")
print(f"{80 * '-'}\n{script}\n{80 * '-'}")
user_input = input("Proceed with execution? (y/N): ").strip().lower()
return user_input == 'y'
if script:
try:
if args.dry_run:
if not confirm_execution(script):
print("Execution cancelled by user.")
return
with io.StringIO() as buf, redirect_stdout(buf):
exec(script, globals())
output = buf.getvalue()
Expand All @@ -35,6 44,7 @@ def banner():
# Main Loop
parser = argparse.ArgumentParser(description='A smart assistant that can execute Python code to help or hurt you.')
parser.add_argument('prompt', nargs='*', help='Prompt for direct execution. If empty, enter conversation mode')
parser.add_argument('--dry-run', action='store_true', help='Print the script before executing and prompt for confirmation.')
args = parser.parse_args()
llm_client = LLMClient() # Will prompt for API key if not found
if len(args.prompt) > 0:
Expand Down

0 comments on commit df2e270

Please sign in to comment.