File tree Expand file tree Collapse file tree 2 files changed +11
-9
lines changed Expand file tree Collapse file tree 2 files changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -74,20 +74,21 @@ def _fetch_value(opts, key):
74
74
return rv
75
75
76
76
77
- def _strategy_command (* command ):
77
+ def _strategy_command (* command : str ):
78
+ """Execute a user-specified command and return its output."""
78
79
import subprocess
79
80
80
- # normalize path of every path member
81
- # if there is no path specified then nothing will happen
82
- command = map (expand_path , command )
81
+ # Normalize path of every path member.
82
+ # If there is no path specified then nothing will happen.
83
+ # Makes this a list to avoid it being exhausted on the first iteration.
84
+ expanded_command = list (map (expand_path , command ))
83
85
84
86
try :
85
- stdout = subprocess .check_output (command , universal_newlines = True )
87
+ stdout = subprocess .check_output (expanded_command , universal_newlines = True )
86
88
return stdout .strip ("\n " )
87
89
except OSError as e :
88
- raise exceptions .UserError (
89
- "Failed to execute command: {}\n {}" .format (" " .join (command ), str (e ))
90
- )
90
+ cmd = " " .join (expanded_command )
91
+ raise exceptions .UserError (f"Failed to execute command: { cmd } \n { str (e )} " )
91
92
92
93
93
94
def _strategy_prompt (text ):
Original file line number Diff line number Diff line change 19
19
_missing = object ()
20
20
21
21
22
- def expand_path (p ):
22
+ def expand_path (p : str ) -> str :
23
+ """Expand $HOME in a path and normalise slashes."""
23
24
p = os .path .expanduser (p )
24
25
p = os .path .normpath (p )
25
26
return p
You can’t perform that action at this time.
0 commit comments