From 331cb547ae24ecd470e89d9aa7c837de72d14444 Mon Sep 17 00:00:00 2001 From: Mikhail Zolotukhin Date: Fri, 11 Oct 2024 21:05:59 -0700 Subject: [PATCH] Show executed commands when --verbose is on. (#38) stack-info: PR: https://github.com/modularml/stack-pr/pull/38, branch: ZolotukhinM/stack/3 --- src/stack_pr/cli.py | 10 +++++++++- src/stack_pr/shell_commands.py | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/stack_pr/cli.py b/src/stack_pr/cli.py index f800033..018002a 100755 --- a/src/stack_pr/cli.py +++ b/src/stack_pr/cli.py @@ -62,7 +62,11 @@ get_gh_username, get_uncommitted_changes, ) -from stack_pr.shell_commands import get_command_output, run_shell_command +from stack_pr.shell_commands import ( + get_command_output, + run_shell_command, + set_show_commands, +) from typing import List, NamedTuple, Optional, Pattern # A bunch of regexps for parsing commit messages and PR descriptions @@ -1380,6 +1384,10 @@ def main(): common_args = CommonArgs.from_args(args) + if common_args.verbose: + # Output shell commands that we run if verbose=True + set_show_commands(True) + check_gh_installed() current_branch = get_current_branch_name() diff --git a/src/stack_pr/shell_commands.py b/src/stack_pr/shell_commands.py index 2fe6cce..9c8ebe1 100644 --- a/src/stack_pr/shell_commands.py +++ b/src/stack_pr/shell_commands.py @@ -4,6 +4,13 @@ ShellCommand = Iterable[Union[str, Path]] +SHOW_COMMANDS = False + + +def set_show_commands(val: bool): + global SHOW_COMMANDS + SHOW_COMMANDS = val + def run_shell_command( cmd: ShellCommand, *, quiet: bool, check: bool = True, **kwargs: Any @@ -30,6 +37,8 @@ def run_shell_command( kwargs.update( {"stdout": subprocess.DEVNULL, "stderr": subprocess.DEVNULL} ) + if SHOW_COMMANDS: + print(f"Running: {cmd}") return subprocess.run(list(map(str, cmd)), **kwargs)