Skip to content

Commit 9ee4963

Browse files
committed
cmd-diff: refactor diff_cmd_output into a loop
It had some common elements so let's use a loop.
1 parent 0bc53dc commit 9ee4963

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/cmd-diff

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -404,15 +404,13 @@ def diff_metal(diff_from, diff_to):
404404
def diff_cmd_outputs(cmd, file_from, file_to):
405405
with tempfile.NamedTemporaryFile(prefix=cmd[0] + '-') as f_from, \
406406
tempfile.NamedTemporaryFile(prefix=cmd[0] + '-') as f_to:
407-
if '{}' not in cmd:
408-
cmd += ['{}']
409-
idx = cmd.index('{}')
410-
cmd_from = list(cmd)
411-
cmd_from[idx] = file_from
412-
subprocess.run(cmd_from, check=True, stdout=f_from).stdout
413-
cmd_to = list(cmd)
414-
cmd_to[idx] = file_to
415-
subprocess.run(cmd_to, check=True, stdout=f_to).stdout
407+
for file, output in (file_from, f_from), (file_to, f_to):
408+
c = list(cmd)
409+
if '{}' not in c:
410+
c += ['{}']
411+
idx = c.index('{}')
412+
c[idx] = file
413+
subprocess.run(c, check=True, stdout=file).stdout
416414
git_diff(f_from.name, f_to.name)
417415

418416

0 commit comments

Comments
 (0)