Skip to content
Snippets Groups Projects
Commit f784d2cd authored by Chris Lamb's avatar Chris Lamb :eyes:
Browse files

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

parent cea78e64
No related branches found
No related tags found
No related merge requests found
......@@ -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 <lamby@debian.org>
#
# 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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# 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 <https://www.gnu.org/licenses/>.
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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment