diff options
author | PJ Eby <distutils-sig@python.org> | 2005-07-08 15:11:19 +0000 |
---|---|---|
committer | PJ Eby <distutils-sig@python.org> | 2005-07-08 15:11:19 +0000 |
commit | ef617190807f0c5387b8151f0c08c6777b1c2b28 (patch) | |
tree | c07245bc97509bc4af13d7091c84d71117001a09 /setuptools/command/alias.py | |
parent | 5eec64a05733986216d87dbdc52c78615ac3cda3 (diff) | |
download | external_python_setuptools-ef617190807f0c5387b8151f0c08c6777b1c2b28.tar.gz external_python_setuptools-ef617190807f0c5387b8151f0c08c6777b1c2b28.tar.bz2 external_python_setuptools-ef617190807f0c5387b8151f0c08c6777b1c2b28.zip |
Restructured the 'alias' command to take arguments instead of options, and
to display the definition of the named alias or of all aliases.
--HG--
branch : setuptools
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041096
Diffstat (limited to 'setuptools/command/alias.py')
-rwxr-xr-x | setuptools/command/alias.py | 69 |
1 files changed, 56 insertions, 13 deletions
diff --git a/setuptools/command/alias.py b/setuptools/command/alias.py index 76daae7f..b184589f 100755 --- a/setuptools/command/alias.py +++ b/setuptools/command/alias.py @@ -3,37 +3,80 @@ from setuptools import Command from distutils.util import convert_path from distutils import log from distutils.errors import * -from setuptools.command.setopt import edit_config, option_base +from setuptools.command.setopt import edit_config, option_base, config_file class alias(option_base): """Define a shortcut that invokes one or more commands""" description = "define a shortcut to invoke one or more commands" + command_consumes_arguments = True user_options = [ - ('alias=', 'a', 'the name of the new pseudo-command'), - ('command=', 'c', 'command(s) and options to invoke when used'), ('remove', 'r', 'remove (unset) the alias'), ] + option_base.user_options boolean_options = option_base.boolean_options + ['remove'] + def initialize_options(self): option_base.initialize_options(self) - self.alias = None - self.command = None + self.args = None self.remove = None + def finalize_options(self): option_base.finalize_options(self) - if self.alias is None: - raise DistutilsOptionError("Must specify name (--alias/-a)") - if self.command is None and not self.remove: - raise DistutilsOptionError("Must specify --command or --remove") + if self.remove and len(self.args)<>1: + raise DistutilsOptionError( + "Must specify exactly one argument (the alias name) when " + "using --remove" + ) + + + + + + + def run(self): - edit_config( - self.filename, {'aliases': {self.alias:self.command}}, - self.dry_run - ) + aliases = self.distribution.get_option_dict('aliases') + + if not self.args: + print "Command Aliases" + print "---------------" + for alias in aliases: + print "setup.py alias", format_alias(alias, aliases) + return + + elif len(self.args)==1: + alias, = self.args + if self.remove: + command = None + elif alias in aliases: + print "setup.py alias", format_alias(alias, aliases) + return + else: + print "No alias definition found for %r" % alias + return + else: + alias = self.args[0] + command = ' '.join(map(repr,self.args[1:])) + + edit_config(self.filename, {'aliases': {alias:command}}, self.dry_run) + + +def format_alias(name, aliases): + source, command = aliases[name] + if source == config_file('global'): + source = '--global-config ' + elif source == config_file('user'): + source = '--user-config ' + elif source == config_file('local'): + source = '' + else: + source = '--filename=%r' % source + return source+name+' '+command + + |