pass more details to initialize_app so subclasses can decide what sort of initialization to do
This commit is contained in:
parent
dfe456fa6b
commit
921708980b
|
@ -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
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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():
|
||||
|
|
Loading…
Reference in New Issue