Shell ¶
Provides tasks for shell commands execution - mostly used in YAML syntax and in Python modules.
:sh ¶
Package to import |
Single task to import |
PIP package to install |
Stable version |
---|---|---|---|
pip install rkd== SELECT VERSION |
Executes a Bash script. Can be multi-line. Script can read from stdin instead of
-c
switch, if configured with
is_cmd_required
=
True
during configuration stage.
Hint
Phrase %RKD% is replaced with an rkd binary name
Hint
This is an extendable task. Read more in Extending tasks chapter.
Example of plain usage:
rkd :sh -c "ps aux"
Example of task alias usage:
from rkd.core.api.syntax import TaskAliasDeclaration as Task
#
# Example of Makefile-like syntax
#
IMPORTS = []
TASKS = [
Task(':find-images', [
':sh', '-c', 'find ../../ -name \'*.png\''
]),
Task(':build', [':sh', '-c', ''' set -x;
cd ../../../
chmod +x setup.py
./setup.py build
ls -la
''']),
# https://github.com/riotkit-org/riotkit-do/issues/43
Task(':hello', [':sh', '-c', 'echo "Hello world"']),
Task(':alias-in-alias-test', [':hello'])
]
:exec ¶
Package to import |
Single task to import |
PIP package to install |
Stable version |
---|---|---|---|
pip install rkd== SELECT VERSION |
Works identically as :sh , but for spawns a single process. Does not allow a multi-line script syntax.
BaseShellCommandWithArgumentParsingTask ¶
Warning
To be used only in Python syntax
Creates a command that executes bash script and provides argument parsing using Python’s argparse. Parsed arguments are registered as ARG_{{argument_name}} eg. –activity-type would be exported as ARG_ACTIVITY_TYPE.
IMPORTS += [
BaseShellCommandWithArgumentParsingTask(
name=":protest",
group=":activism",
description="Take action!",
arguments_definition=lambda argparse: (
argparse.add_argument('--activity-type', '-t', help='Select an activity type')
),
command='''
echo "Let's act! Let's ${ARG_ACTIVITY_TYPE}!"
'''
)
]
MultiStepLanguageAgnosticTask ¶
Used by default in YAML syntax (if “extends” is not specified). Allows to execute multiple steps in various languages.
It has very similar behavior to the GNU Makefile - each step is ran in a separate shell.
- class rkd.core.standardlib.syntax. MultiStepLanguageAgnosticTask [source] ¶
-
Allows to define multiple shell/other language steps In YAML syntax it is a default task type (notice: there is no need to specify extends attribute)
Bash example
version: org.riotkit.rkd/yaml/v2 tasks: :example: steps: | echo "Hello from the Bash"
Python example
version: org.riotkit.rkd/yaml/v2 tasks: :example: steps: | #!python print('Hello')
Multiple languages and steps example
version: org.riotkit.rkd/yaml/v2 tasks: :example: steps: - | #!python print('Hello from Python') - ps aux - echo "Hello from Bash"
Non-standard languages support
version: org.riotkit.rkd/yaml/v2 imports: - rkd.php.script.PhpLanguage environment: PHP: '8.0' IMAGE: 'php' tasks: :example: steps: - | #!rkd.php.script.PhpLanguage phpinfo(); - | #!rkd.core.standardlib.jinja.Jinja2Language The used shell is {{ SHELL }}