Compare commits
3 commits
c118227942
...
1bb1c7934b
Author | SHA1 | Date | |
---|---|---|---|
|
1bb1c7934b | ||
|
974156ccde | ||
|
25ef5d5a5f |
2 changed files with 38 additions and 0 deletions
14
README.md
14
README.md
|
@ -336,6 +336,7 @@ fine-grained control.
|
||||||
| `stdin` | Allow a command to read from standard input (default: false) |
|
| `stdin` | Allow a command to read from standard input (default: false) |
|
||||||
| `stdout` | Show a command's output from stdout (default: false) |
|
| `stdout` | Show a command's output from stdout (default: false) |
|
||||||
| `stderr` | Show a command's error output from stderr (default: false) |
|
| `stderr` | Show a command's error output from stderr (default: false) |
|
||||||
|
| `if` | Run command if a condition is true (default: true) (optional) |
|
||||||
|
|
||||||
Note that `quiet` controls whether the command (a string) is printed in log
|
Note that `quiet` controls whether the command (a string) is printed in log
|
||||||
output, it does not control whether the output from running the command is
|
output, it does not control whether the output from running the command is
|
||||||
|
@ -360,6 +361,19 @@ printed (that is controlled by `stdout` / `stderr`). When a command's `stdin` /
|
||||||
stderr: true
|
stderr: true
|
||||||
```
|
```
|
||||||
|
|
||||||
|
##### Running shell command conditionally
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- shell:
|
||||||
|
- command: apt update && apt upgrade -y
|
||||||
|
if: lsb_release -i | grep -io 'debian'
|
||||||
|
description: Update APT package repository
|
||||||
|
|
||||||
|
- command: dnf update -y
|
||||||
|
if: lsb_release -i | grep -io 'fedora'
|
||||||
|
description: Update DNF package repository
|
||||||
|
```
|
||||||
|
|
||||||
### Clean
|
### Clean
|
||||||
|
|
||||||
Clean commands specify directories that should be checked for dead symbolic
|
Clean commands specify directories that should be checked for dead symbolic
|
||||||
|
|
|
@ -34,6 +34,30 @@ class Shell(Plugin):
|
||||||
stdout = item.get("stdout", stdout)
|
stdout = item.get("stdout", stdout)
|
||||||
stderr = item.get("stderr", stderr)
|
stderr = item.get("stderr", stderr)
|
||||||
quiet = item.get("quiet", quiet)
|
quiet = item.get("quiet", quiet)
|
||||||
|
|
||||||
|
# run shell command if the 'if' key is present
|
||||||
|
# Ex:
|
||||||
|
# - shell:
|
||||||
|
# - command: echo "This computer is a Mac"
|
||||||
|
# if: uname -s | grep -i "Darwin"
|
||||||
|
#
|
||||||
|
# Ex: skipping shell command
|
||||||
|
# - shell:
|
||||||
|
# - command: echo "skip this shell command"
|
||||||
|
# if: false
|
||||||
|
if "if" in item:
|
||||||
|
run_if_result = dotbot.util.shell_command(
|
||||||
|
str(item["if"]), # this to make sure python doesn't run it. Had a odd behaviour with having the value 'false'. Check Pull Request #321
|
||||||
|
cwd=self._context.base_directory(),
|
||||||
|
enable_stdin=False,
|
||||||
|
enable_stdout=False,
|
||||||
|
enable_stderr=stderr,
|
||||||
|
)
|
||||||
|
|
||||||
|
# if the condition to run the command is false,
|
||||||
|
# skip running the command
|
||||||
|
if run_if_result != 0:
|
||||||
|
continue
|
||||||
elif isinstance(item, list):
|
elif isinstance(item, list):
|
||||||
cmd = item[0]
|
cmd = item[0]
|
||||||
msg = item[1] if len(item) > 1 else None
|
msg = item[1] if len(item) > 1 else None
|
||||||
|
|
Loading…
Reference in a new issue