Skip to content

Commit

Permalink
Show executed commands when --verbose is on.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZolotukhinM committed Oct 8, 2024
1 parent a6c5504 commit d03cb68
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/stack_pr/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1374,6 +1378,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()
Expand Down
9 changes: 9 additions & 0 deletions src/stack_pr/shell_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)


Expand Down

0 comments on commit d03cb68

Please sign in to comment.