restore -i

This commit is contained in:
2019-09-22 11:25:50 -04:00
parent 674457d02e
commit fdf7caab33
2 changed files with 11 additions and 14 deletions
+4 -4
View File
@@ -545,18 +545,18 @@ class TaskScript(BaseAction):
args = " ".join([shlex_quote(a) for a in self.bashfile.args])
args = args if args else "\b"
sed_magic = "sed >&2 's/^/ | /'" if not silent else "sed >&2 's/^//'"
sed_magic = "2>&1 | sed >&2 's/^/ | /'" if not (silent or interactive) else ""
script = (
f"t=$(mktemp) && bake --source {self.name} "
f"> $t && chmod +x $t && $t {args} 2>&1 | "
f"{sed_magic}" + ' && exit "${PIPESTATUS[1]}"; rm -fr $t'
"> ${t} && chmod +x ${t} && ${t} " + f"{args}" + " && EXIT=${?} "
f"{sed_magic}" + "; rm -fr ${t} && exit ${EXIT}"
)
if debug:
click.echo(f" {click.style('$', fg='green')} {script}", err=True)
bash = Bash()
bash = Bash(interactive=interactive)
return bash.command(script, quote=False)
@property
+7 -10
View File
@@ -130,13 +130,11 @@ class BashProcess:
class Bash:
"""an instance of bash"""
def __init__(self, *, path=WHICH_BASH, environ=None):
def __init__(self, *, path=WHICH_BASH, environ=None, **kwargs):
"""constructor"""
self.path = path
self.environ = environ or {}
ver_proc = self("--version")
self.about = ver_proc.output
self.kwargs = kwargs
@property
def version(self) -> str:
@@ -145,16 +143,15 @@ class Bash:
# ...GNU Bash, version 4.4.19(1)-release ... --> 4.4.19(1)-release
return matches.group(1) if matches else "version_unknown"
@property
def about(self):
return self("--version").output
def __call__(self, *args) -> BashProcess:
"""execute the bash process as a child of this process"""
return BashProcess(parent=self, args=args)
return BashProcess(parent=self, args=args, **self.kwargs)
def command(self, script: str, quote=True) -> BashProcess:
"""form up the command with shlex and execute"""
maybe_quote = shlex_quote if quote else str
return self(f"-c", maybe_quote(script))
def run(script=None, **kwargs):
"""Runs the given bash script."""
return Bash(**kwargs).command(script)