Commit 3a5c6f95 authored by Godefroid Chapelle's avatar Godefroid Chapelle

avoid explicit list of commands

as suggested by @leorochael
parent 0d56ba28
...@@ -50,6 +50,19 @@ if PY3: ...@@ -50,6 +50,19 @@ if PY3:
else: else:
text_type = unicode text_type = unicode
def command(method):
method.buildout_command = True
return method
def commands(cls):
for name, method in cls.__dict__.items():
if hasattr(method, "buildout_command"):
cls.COMMANDS.add(name)
return cls
def _print_options(sep=' ', end='\n', file=None): def _print_options(sep=' ', end='\n', file=None):
return sep, end, file return sep, end, file
...@@ -289,8 +302,11 @@ _buildout_default_options = _annotate_section({ ...@@ -289,8 +302,11 @@ _buildout_default_options = _annotate_section({
}, 'DEFAULT_VALUE') }, 'DEFAULT_VALUE')
@commands
class Buildout(DictMixin): class Buildout(DictMixin):
COMMANDS = set()
def __init__(self, config_file, cloptions, def __init__(self, config_file, cloptions,
user_defaults=True, user_defaults=True,
command=None, args=()): command=None, args=()):
...@@ -555,6 +571,7 @@ class Buildout(DictMixin): ...@@ -555,6 +571,7 @@ class Buildout(DictMixin):
return name return name
return os.path.join(self._buildout_dir, name) return os.path.join(self._buildout_dir, name)
@command
def bootstrap(self, args): def bootstrap(self, args):
__doing__ = 'Bootstrapping.' __doing__ = 'Bootstrapping.'
...@@ -628,11 +645,13 @@ class Buildout(DictMixin): ...@@ -628,11 +645,13 @@ class Buildout(DictMixin):
f.write('[buildout]\nparts =\n') f.write('[buildout]\nparts =\n')
f.close() f.close()
@command
def init(self, args): def init(self, args):
self.bootstrap(()) self.bootstrap(())
if args: if args:
self.install(()) self.install(())
@command
def install(self, install_args): def install(self, install_args):
__doing__ = 'Installing.' __doing__ = 'Installing.'
...@@ -1210,6 +1229,7 @@ class Buildout(DictMixin): ...@@ -1210,6 +1229,7 @@ class Buildout(DictMixin):
print_("Picked versions have been written to " + print_("Picked versions have been written to " +
self.update_versions_file) self.update_versions_file)
@command
def setup(self, args): def setup(self, args):
if not args: if not args:
raise zc.buildout.UserError( raise zc.buildout.UserError(
...@@ -1236,8 +1256,11 @@ class Buildout(DictMixin): ...@@ -1236,8 +1256,11 @@ class Buildout(DictMixin):
os.close(fd) os.close(fd)
os.remove(tsetup) os.remove(tsetup)
runsetup = setup # backward compat. @command
def runsetup(self, args):
self.setup(args)
@command
def query(self, args=None): def query(self, args=None):
if args is None or len(args) != 1: if args is None or len(args) != 1:
_error('The query command requires a single argument.') _error('The query command requires a single argument.')
...@@ -1259,6 +1282,7 @@ class Buildout(DictMixin): ...@@ -1259,6 +1282,7 @@ class Buildout(DictMixin):
else: else:
_error('Section not found:', section) _error('Section not found:', section)
@command
def annotate(self, args=None): def annotate(self, args=None):
verbose = self['buildout'].get('verbosity', 0) != 0 verbose = self['buildout'].get('verbosity', 0) != 0
section = None section = None
...@@ -2138,10 +2162,7 @@ def main(args=None): ...@@ -2138,10 +2162,7 @@ def main(args=None):
if args: if args:
command = args.pop(0) command = args.pop(0)
if command not in ( if command not in Buildout.COMMANDS:
'install', 'bootstrap', 'runsetup', 'setup', 'init',
'annotate', 'query',
):
_error('invalid command:', command) _error('invalid command:', command)
else: else:
command = 'install' command = 'install'
......
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