pass more details to initialize_app so subclasses can decide what sort of initialization to do

This commit is contained in:
Doug Hellmann 2012-05-10 14:58:18 -04:00
parent dfe456fa6b
commit 921708980b
4 changed files with 12 additions and 4 deletions

View File

@ -137,7 +137,7 @@ class App(object):
"""
self.options, remainder = self.parser.parse_known_args(argv)
self.configure_logging()
self.initialize_app()
self.initialize_app(remainder)
result = 1
if not remainder:
result = self.interact()
@ -147,10 +147,13 @@ class App(object):
# FIXME(dhellmann): Consider moving these command handling methods
# to a separate class.
def initialize_app(self):
def initialize_app(self, argv):
"""Hook for subclasses to take global initialization action
after the arguments are parsed but before a command is run.
Invoked only once, even in interactive mode.
:param argv: List of arguments, including the subcommand to run.
Empty for interactive mode.
"""
return

View File

@ -16,7 +16,7 @@ class DemoApp(App):
command_manager=CommandManager('cliff.demo'),
)
def initialize_app(self):
def initialize_app(self, argv):
self.log.debug('initialize_app')
def prepare_to_run_command(self, cmd):

View File

@ -2,6 +2,11 @@
Release History
=================
dev
- Pass the non-global argument list to :func:`initialize_app` to be
used in initialization work.
0.5.1
- Remove pinned version requirement for PrettyTable until the

View File

@ -48,7 +48,7 @@ def test_initialize_app():
app, command = make_app()
app.initialize_app = mock.MagicMock(name='initialize_app')
app.run(['mock'])
app.initialize_app.assert_called_once_with()
app.initialize_app.assert_called_once_with(['mock'])
def test_prepare_to_run_command():