Эх сурвалжийг харах

Add ability to add argument to shell command in shell neuron

Raphael Khaiat 8 жил өмнө
parent
commit
5709002f9a

+ 16 - 0
kalliope/neurons/shell/README.md

@@ -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
@@ -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

+ 4 - 0
kalliope/neurons/shell/shell.py

@@ -39,6 +39,10 @@ class Shell(NeuronModule):
         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():