1
0
Fork 0
mirror of synced 2024-11-22 16:25:34 -05:00

Merge branch 'thtliife/suppress-shell-cmd'

This commit is contained in:
Anish Athalye 2018-11-21 19:50:46 -05:00
commit 5e2d40939e
3 changed files with 41 additions and 2 deletions

View file

@ -281,8 +281,9 @@ shell command and the second is an optional human-readable description.
Shell commands support an extended syntax as well, which provides more Shell commands support an extended syntax as well, which provides more
fine-grained control. A command can be specified as a dictionary that contains fine-grained control. A command can be specified as a dictionary that contains
the command to be run, a description, and whether `stdin`, `stdout`, and the command to be run, a description, whether to suppress outputting the
`stderr` are enabled. In this syntax, all keys are optional except for the command in the display via `quiet`, and whether `stdin`, `stdout`,
and `stderr` are enabled. In this syntax, all keys are optional except for the
command itself. command itself.
#### Example #### Example
@ -296,6 +297,7 @@ command itself.
stdin: true stdin: true
stdout: true stdout: true
description: Reading and printing variable description: Reading and printing variable
quiet: true
- -
command: read fail command: read fail
stderr: true stderr: true

View file

@ -22,12 +22,15 @@ class Shell(dotbot.Plugin):
with open(os.devnull, 'w') as devnull: with open(os.devnull, 'w') as devnull:
for item in data: for item in data:
stdin = stdout = stderr = devnull stdin = stdout = stderr = devnull
quiet = False
if defaults.get('stdin', False) == True: if defaults.get('stdin', False) == True:
stdin = None stdin = None
if defaults.get('stdout', False) == True: if defaults.get('stdout', False) == True:
stdout = None stdout = None
if defaults.get('stderr', False) == True: if defaults.get('stderr', False) == True:
stderr = None stderr = None
if defaults.get('quiet', False) == True:
quiet = True
if isinstance(item, dict): if isinstance(item, dict):
cmd = item['command'] cmd = item['command']
msg = item.get('description', None) msg = item.get('description', None)
@ -37,6 +40,8 @@ class Shell(dotbot.Plugin):
stdout = None if item['stdout'] == True else devnull stdout = None if item['stdout'] == True else devnull
if 'stderr' in item: if 'stderr' in item:
stderr = None if item['stderr'] == True else devnull stderr = None if item['stderr'] == True else devnull
if 'quiet' in item:
quiet = True if item['quiet'] == True else False
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
@ -45,6 +50,8 @@ class Shell(dotbot.Plugin):
msg = None msg = None
if msg is None: if msg is None:
self._log.lowinfo(cmd) self._log.lowinfo(cmd)
elif quiet:
self._log.lowinfo('%s' % msg)
else: else:
self._log.lowinfo('%s [%s]' % (msg, cmd)) self._log.lowinfo('%s [%s]' % (msg, cmd))
executable = os.environ.get('SHELL') executable = os.environ.get('SHELL')

View file

@ -0,0 +1,30 @@
test_description='shell command can be suppressed in output'
. '../test-lib.bash'
# when not quiet, expect to see command that was run
test_expect_success 'run' '
(run_dotbot | grep "echo banana") <<EOF
- shell:
- command: echo banana
description: echoing a thing...
EOF
'
# when quiet, expect command to be suppressed
test_expect_success 'run 2' '
(run_dotbot | (! grep "echo banana")) <<EOF
- shell:
- command: echo banana
description: echoing a thing...
quiet: true
EOF
'
# when no description, expect to see command
test_expect_success 'run 3' '
(run_dotbot | grep "echo banana") <<EOF
- shell:
- command: echo banana
quiet: true
EOF
'