diff options
author | Lars Wirzenius <liw@liw.fi> | 2023-07-08 16:45:01 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2023-07-08 20:12:27 +0300 |
commit | 994647ea63959a1bcff19e58f535dc69c95c69ec (patch) | |
tree | b7dc08e07869890cf8ab57083fb3578a4c300a1c | |
parent | 57ed2ab04d43981959560f3a03828b36a4a35f0a (diff) | |
download | v-i-994647ea63959a1bcff19e58f535dc69c95c69ec.tar.gz |
feat: log prettier when running commands
Sponsored-by: author
-rwxr-xr-x | v-i | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -33,14 +33,25 @@ def error(msg): def run(argv, **kwargs): - log(f"RUN: {argv} {kwargs}") + log(f"RUN: {argv[0]}") + for arg in argv: + log(f"RUN: - {arg!r}") + for key in kwargs: + log(f"RUN: - {key}={kwargs[key]!r}") check = False - if "check" in kwargs: + if kwargs.get("check"): check = True del kwargs["check"] + if "capture_output" not in kwargs: + kwargs["capture_output"] = True p = subprocess.run(argv, **kwargs) if check and p.returncode != 0: - error(f"Ran command that failed: {argv}\n{p.stderr.decode()}") + stdout = indent(p.stdout.decode()) + stderr = indent(p.stderr.decode()) + error(f"Ran command that failed: {argv}") + error(f"Exit code {p.returncode}") + error(f"Stdout:\n{stdout}") + error(f"Stderr:\n{stderr}") sys.exit("command failed") return p |