pieces-app / cli-agent

Pieces CLI for interacting with Pieces OS
https://docs.pieces.app/extensions-plugins/cli
MIT License
60 stars 23 forks source link

Command to execute a snippet #35 #169

Closed sambhavnoobcoder closed 3 months ago

sambhavnoobcoder commented 3 months ago

Description

This PR addresses issue #35 by implementing a new 'run' command in the Pieces CLI that allows users to directly execute their saved bash snippets in the terminal.

Problem:

Users want a quick way to execute their saved bash snippets without having to manually copy and paste them into the terminal.

Solution:

We've implemented a new ExecuteCommand class that allows users to execute a snippet by its name directly from the Pieces CLI. This is achieved through two new files: run_shell_command.py and run_bash_command.py.

Changes:

  1. run_shell_command.py (new file):

    • Implements ExecuteCommand class for executing shell commands
    • Includes methods for asset retrieval, selection, and execution
    • Uses subprocess to run commands with shell=True
  2. run_bash_command.py (new file):

    • Similar to run_shell_command.py, but executes commands in bash
    • Uses subprocess to run commands with ['bash', '-c', command]

Key features:

Implementation details:

bishoy-at-pieces commented 3 months ago

LGTM but seems there is a lot of duplicate code

sambhavnoobcoder commented 3 months ago

so far we are working on only shell scripts since Bash scripting is a subset of shell scripting . So most of the common bash commands would easily on the shell implementation itself , without any difference to the expected behaviour . Also , since shell is almost entirely compliant with the POSIX standards and bash is also nearly fully POSIX compliant ( bash version 4.0 and later have been made fully POSIX compliant) so we only have a very few scripts that might give error to the above implementation(Only a smaller niche of commands that may not have been upgraded , deprecations , etc .) . Hence I would suggest , that we could solve this with a simple try - catch statement , so that in case a command execution fails with the shell , it is then given to the bash implementation , and if that fails , it is concluded to be in an incorrect format . Considering the size of/ number of edge cases expected here Is small , I would think this to very feasible as well .

If you think this is a valid solution , I'll start coding it out , else if you have any other suggestion , I'd be glad to give that approach a look as well .

bishoy-at-pieces commented 3 months ago

Alr if so I would like to add the bash commands to the list too