@@ -72,7 +72,7 @@ def _fetch_value(opts, key):
7272 return rv
7373
7474
75- def _strategy_command (* command : str ):
75+ def _strategy_command (* command : str , shell : bool = False ):
7676 """Execute a user-specified command and return its output."""
7777 import subprocess
7878
@@ -82,18 +82,26 @@ def _strategy_command(*command: str):
8282 expanded_command = list (map (expand_path , command ))
8383
8484 try :
85- stdout = subprocess .check_output (expanded_command , universal_newlines = True )
85+ stdout = subprocess .check_output (
86+ expanded_command , universal_newlines = True , shell = shell
87+ )
8688 return stdout .strip ("\n " )
8789 except OSError as e :
8890 cmd = " " .join (expanded_command )
8991 raise exceptions .UserError (f"Failed to execute command: { cmd } \n { str (e )} " )
9092
9193
94+ def _strategy_shell (* command : str ):
95+ """Execute a user-specified command string in a shell and return its output."""
96+ return _strategy_command (* command , shell = True )
97+
98+
9299def _strategy_prompt (text ):
93100 return click .prompt (text , hide_input = True )
94101
95102
96103STRATEGIES = {
97104 "command" : _strategy_command ,
105+ "shell" : _strategy_shell ,
98106 "prompt" : _strategy_prompt ,
99107}
0 commit comments