Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to add argument to shell command in shell neuron #132

Merged
merged 1 commit into from Dec 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions kalliope/neurons/shell/README.md
Expand Up @@ -11,6 +11,7 @@ Run a shell command on the local system where Kalliope is installed.
|-----------|----------|---------|----------|-----------------------------------------------------------------------------|
| cmd | yes | | | The shell command to run |
| async | no | False | | If True, Kalliope will not wait for the end of the execution of the command |
| query | no | False | | An argument to send the script. |


## Return Values
Expand Down Expand Up @@ -89,6 +90,21 @@ If you run it a second time, the command will fail as the file is not anymore pr
file_template: remove_file.j2
```

If you want to add argument to your shell command, you can use the query arguments.
```
- name: "Delete-a-specific-file"
signals:
- order: "remove file {{ query }}"
neurons:
- shell:
cmd: "rm "
file_template: remove_file.j2
args:
- query
```
In the example above, kalliope will remove the file you asked for in the query.
eg: "remove file test", the executed command will be "rm test"

## Templates example

Template `remove_file.j2` used in the remove file example remove_file.j2
Expand Down
4 changes: 4 additions & 0 deletions kalliope/neurons/shell/shell.py
Expand Up @@ -39,6 +39,10 @@ def __init__(self, **kwargs):
self.cmd = kwargs.get('cmd', None)
# get if the user select a blocking command or not
self.async = kwargs.get('async', False)
self.query = kwargs.get('query', None)

if self.query is not None:
self.cmd = self.cmd + "\"" + self.query +"\""

# check parameters
if self._is_parameters_ok():
Expand Down