in utils/preflight_check.py [0:0]
def pretty_print_cmd(command_union: Optional[Union[list[str], list[list[str]]]]):
"""Pretty print the cmd. It could be a nested array."""
if not command_union:
return
# Check for nested commands.
if isinstance(command_union[0], list):
for subcommand in command_union:
assert isinstance(subcommand, list)
# Recurse into the subcommand
pretty_print_cmd(subcommand)
return
command: list[str] = command_union # type: ignore
# This command is not useful to display.
if " ".join(command) == "chmod +x run-task":
return
# Many commands are invoked by bash. Hide that in the output.
# Example:
# ['/usr/local/bin/run-task', '--translations-checkout=/builds/worker/checkouts/vcs/',
# '--task-cwd', '/builds/worker/checkouts/vcs', '--', 'bash', '-cx', 'make validate-taskgraph']
try:
index = command.index("bash")
print(command)
command = command[index + 2 :]
except ValueError:
pass
try:
index = command.index("/builds/worker/checkouts")
command = command[index + 2 :]
except ValueError:
pass
# This is a bit of a hacky way to not create a newline for `--`.
delimiter = "#-#-#-#-#-#-#-#-#-#-#-#"
if delimiter in command:
raise Exception("Delimiter found in command, change the delimiter")
subcommands = []
for subcommand in " ".join(command).split("&&"):
subcommands.append(
(
subcommand
# No newlines for `command.sh -- extra_args`.
.replace("-- ", delimiter)
# Remove whitespace.
.strip()
# Create newlines for flags.
.replace("--", "\\\n --")
# Put the `--` back.
.replace(delimiter, "-- ")
)
)
command_text = "\n ".join(subcommands)
print(f" {term.gray(command_text)}")