Skip to content

Commit

Permalink
Integrate shell command execution in CLI and autocomplete support
Browse files Browse the repository at this point in the history
In this commit, we've added a new feature to our CLI in `aicodebot/cli.py` that allows users to execute shell commands directly. This is done by typing `/sh` followed by the desired command. We've also ensured that empty commands are handled gracefully.

In addition, we've updated the autocomplete functionality in `aicodebot/coder.py` to include the new `/sh` command. This will provide a smoother user experience when using the CLI. 🚀👩‍💻
  • Loading branch information
TechNickAI committed Jul 27, 2023
1 parent fc74d5e commit a8ba588
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions aicodebot/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,17 @@ def calc_response_token_size(files):
ctx = click.get_current_context()
ctx.invoke(review, *args)
continue
elif cmd == "/sh":
# Strip off the /sh and any leading/trailing whitespace
shell_command = human_input[3:].strip()

if not shell_command:
continue

# Execute the shell command and let the output go directly to the console
subprocess.run(shell_command, shell=True) # noqa: S602
continue

elif cmd == "/quit":
break

Expand Down
2 changes: 1 addition & 1 deletion aicodebot/coder.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ def get_completions(self, document, complete_event):
# Get the text before the cursor
text = document.text_before_cursor

supported_commands = ["/add", "/commit", "/drop", "/edit", "/files", "/review", "/quit"]
supported_commands = ["/add", "/commit", "/drop", "/edit", "/files", "/review", "/sh", "/quit"]

# If the text starts with a slash, it's a command
if text.startswith("/"):
Expand Down

1 comment on commit a8ba588

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AICodeBot Review Comments:

Great job on integrating shell command execution in CLI and autocomplete support! The code is clean and understandable. The addition of the /sh command to the supported commands list in aicodebot/coder.py enhances the user experience. Also, handling of empty commands in aicodebot/cli.py is a good practice to avoid unnecessary errors. However, the use of subprocess.run(shell_command, shell=True) could potentially be a security risk as it allows shell injection. It would be better to use a safer alternative or ensure that the input is properly sanitized before execution. Keep up the good work! 😊👍

Code review automatically created with AICodeBot

Please sign in to comment.