Merge branch 'etkeys/feature/cli-force-shell-out-err-true'
This commit is contained in:
commit
43b62ed532
3 changed files with 101 additions and 5 deletions
|
@ -1,7 +1,7 @@
|
|||
import os, glob
|
||||
import sys
|
||||
|
||||
from argparse import ArgumentParser
|
||||
from argparse import ArgumentParser, RawTextHelpFormatter
|
||||
from .config import ConfigReader, ReadingError
|
||||
from .dispatcher import Dispatcher, DispatchError
|
||||
from .messenger import Messenger
|
||||
|
@ -16,8 +16,10 @@ def add_options(parser):
|
|||
help='suppress almost all output')
|
||||
parser.add_argument('-q', '--quiet', action='store_true',
|
||||
help='suppress most output')
|
||||
parser.add_argument('-v', '--verbose', action='store_true',
|
||||
help='enable verbose output')
|
||||
parser.add_argument('-v', '--verbose', action='count', default=0,
|
||||
help='enable verbose output\n'
|
||||
'-v: typical verbose\n'
|
||||
'-vv: also, set shell commands stderr/stdout to true')
|
||||
parser.add_argument('-d', '--base-directory',
|
||||
help='execute commands from within BASEDIR',
|
||||
metavar='BASEDIR')
|
||||
|
@ -47,7 +49,7 @@ def read_config(config_file):
|
|||
def main():
|
||||
log = Messenger()
|
||||
try:
|
||||
parser = ArgumentParser()
|
||||
parser = ArgumentParser(formatter_class=RawTextHelpFormatter)
|
||||
add_options(parser)
|
||||
options = parser.parse_args()
|
||||
if options.version:
|
||||
|
@ -57,7 +59,7 @@ def main():
|
|||
log.set_level(Level.WARNING)
|
||||
if options.quiet:
|
||||
log.set_level(Level.INFO)
|
||||
if options.verbose:
|
||||
if options.verbose > 0:
|
||||
log.set_level(Level.DEBUG)
|
||||
|
||||
if options.force_color and options.no_color:
|
||||
|
|
|
@ -10,6 +10,7 @@ class Shell(dotbot.Plugin):
|
|||
'''
|
||||
|
||||
_directive = 'shell'
|
||||
_has_shown_override_message = False
|
||||
|
||||
def can_handle(self, directive):
|
||||
return directive == self._directive
|
||||
|
@ -23,6 +24,7 @@ class Shell(dotbot.Plugin):
|
|||
def _process_commands(self, data):
|
||||
success = True
|
||||
defaults = self._context.defaults().get('shell', {})
|
||||
options = self._get_option_overrides()
|
||||
for item in data:
|
||||
stdin = defaults.get('stdin', False)
|
||||
stdout = defaults.get('stdout', False)
|
||||
|
@ -47,6 +49,8 @@ class Shell(dotbot.Plugin):
|
|||
self._log.lowinfo('%s' % msg)
|
||||
else:
|
||||
self._log.lowinfo('%s [%s]' % (msg, cmd))
|
||||
stdout = options.get('stdout', stdout)
|
||||
stderr = options.get('stderr', stderr)
|
||||
ret = dotbot.util.shell_command(
|
||||
cmd,
|
||||
cwd=self._context.base_directory(),
|
||||
|
@ -62,3 +66,14 @@ class Shell(dotbot.Plugin):
|
|||
else:
|
||||
self._log.error('Some commands were not successfully executed')
|
||||
return success
|
||||
|
||||
def _get_option_overrides(self):
|
||||
ret = {}
|
||||
options = self._context.options()
|
||||
if options.verbose > 1:
|
||||
ret['stderr'] = True
|
||||
ret['stdout'] = True
|
||||
if not self._has_shown_override_message:
|
||||
self._log.debug("Shell: Found cli option to force show stderr and stdout.")
|
||||
self._has_shown_override_message = True
|
||||
return ret
|
||||
|
|
79
test/tests/shell-cli-override-config.bash
Normal file
79
test/tests/shell-cli-override-config.bash
Normal file
|
@ -0,0 +1,79 @@
|
|||
test_description='cli options can override config file'
|
||||
. '../test-lib.bash'
|
||||
|
||||
test_expect_success 'run 1' '
|
||||
(run_dotbot -vv | (grep "^apple")) <<EOF
|
||||
- shell:
|
||||
-
|
||||
command: echo apple
|
||||
EOF
|
||||
'
|
||||
|
||||
test_expect_success 'run 2' '
|
||||
(run_dotbot -vv | (grep "^apple")) <<EOF
|
||||
- shell:
|
||||
-
|
||||
command: echo apple
|
||||
stdout: false
|
||||
EOF
|
||||
'
|
||||
|
||||
test_expect_success 'run 3' '
|
||||
(run_dotbot -vv | (grep "^apple")) <<EOF
|
||||
- defaults:
|
||||
shell:
|
||||
stdout: false
|
||||
- shell:
|
||||
- command: echo apple
|
||||
EOF
|
||||
'
|
||||
|
||||
# Control to make sure stderr redirection is working as expected
|
||||
test_expect_failure 'run 4' '
|
||||
(run_dotbot -vv | (grep "^apple")) <<EOF
|
||||
- shell:
|
||||
- command: echo apple >&2
|
||||
EOF
|
||||
'
|
||||
|
||||
test_expect_success 'run 5' '
|
||||
(run_dotbot -vv 2>&1 | (grep "^apple")) <<EOF
|
||||
- shell:
|
||||
- command: echo apple >&2
|
||||
EOF
|
||||
'
|
||||
|
||||
test_expect_success 'run 6' '
|
||||
(run_dotbot -vv 2>&1 | (grep "^apple")) <<EOF
|
||||
- shell:
|
||||
-
|
||||
command: echo apple >&2
|
||||
stdout: false
|
||||
EOF
|
||||
'
|
||||
|
||||
test_expect_success 'run 7' '
|
||||
(run_dotbot -vv 2>&1 | (grep "^apple")) <<EOF
|
||||
- defaults:
|
||||
shell:
|
||||
stdout: false
|
||||
- shell:
|
||||
- command: echo apple >&2
|
||||
EOF
|
||||
'
|
||||
|
||||
# Make sure that we must use verbose level 2
|
||||
# This preserves backwards compatability
|
||||
test_expect_failure 'run 8' '
|
||||
(run_dotbot -v | (grep "^apple")) <<EOF
|
||||
- shell:
|
||||
- command: echo apple
|
||||
EOF
|
||||
'
|
||||
|
||||
test_expect_failure 'run 9' '
|
||||
(run_dotbot -v | (grep "^apple")) <<EOF
|
||||
- shell:
|
||||
- command: echo apple >&2
|
||||
EOF
|
||||
'
|
Loading…
Reference in a new issue