From 1d7b59f5172a215ad9961e2eb8bbd1756b941a5f Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Fri, 8 Jul 2005 15:49:53 +0000 Subject: Cleaner argument quoting in command aliases. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041098 --- setuptools/command/alias.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/setuptools/command/alias.py b/setuptools/command/alias.py index b184589f..f5368b29 100755 --- a/setuptools/command/alias.py +++ b/setuptools/command/alias.py @@ -5,6 +5,15 @@ from distutils import log from distutils.errors import * from setuptools.command.setopt import edit_config, option_base, config_file +def shquote(arg): + """Quote an argument for later parsing by shlex.split()""" + for c in '"', "'", "\\", "#": + if c in arg: return repr(arg) + if arg.split()<>[arg]: + return repr(arg) + return arg + + class alias(option_base): """Define a shortcut that invokes one or more commands""" @@ -17,13 +26,11 @@ class alias(option_base): boolean_options = option_base.boolean_options + ['remove'] - def initialize_options(self): option_base.initialize_options(self) self.args = None self.remove = None - def finalize_options(self): option_base.finalize_options(self) if self.remove and len(self.args)<>1: @@ -32,13 +39,6 @@ class alias(option_base): "using --remove" ) - - - - - - - def run(self): aliases = self.distribution.get_option_dict('aliases') @@ -61,7 +61,7 @@ class alias(option_base): return else: alias = self.args[0] - command = ' '.join(map(repr,self.args[1:])) + command = ' '.join(map(shquote,self.args[1:])) edit_config(self.filename, {'aliases': {alias:command}}, self.dry_run) -- cgit v1.2.1