Commit f784d2cd authored by Chris Lamb's avatar Chris Lamb 💬

Split out command-line formatting into a separate utility function.

parent cea78e64
......@@ -22,6 +22,8 @@ import logging
import shlex
import subprocess
from ...utils import format_cmdline
logger = logging.getLogger(__name__)
......@@ -65,16 +67,9 @@ class Command(metaclass=abc.ABCMeta):
def cmdline(self):
raise NotImplementedError()
def shell_cmdline(self):
def fn(x):
if x == self.path:
return '{}'
x = repr(x)
if ' ' not in x:
x = x[1:-1]
return x
return ' '.join(fn(x) for x in self.cmdline())
def shell_cmdline(self, *args, **kwargs):
kwargs.setdefault('replace', (self.path,))
return format_cmdline(self.cmdline(), *args, **kwargs)
def env(self):
return None # inherit parent environment by default
# -*- coding: utf-8 -*-
# diffoscope: in-depth comparison of files, archives, and directories
# Copyright © 2019 Chris Lamb <>
# diffoscope is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# diffoscope is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with diffoscope. If not, see <>.
def format_cmdline(cmd, replace=()):
def fn(x):
if x in replace:
return '{}'
x = repr(x)
if ' ' not in x:
x = x[1:-1]
return x
return ' '.join(fn(x) for x in cmd)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment