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)