From 921708980b2e7309f5c92831b467768370158714 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Thu, 10 May 2012 14:58:18 -0400 Subject: pass more details to initialize_app so subclasses can decide what sort of initialization to do --- cliff/app.py | 7 +++++-- demoapp/cliffdemo/main.py | 2 +- docs/source/history.rst | 5 +++++ tests/test_app.py | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cliff/app.py b/cliff/app.py index eec2d5c..cd2386c 100644 --- a/cliff/app.py +++ b/cliff/app.py @@ -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 diff --git a/demoapp/cliffdemo/main.py b/demoapp/cliffdemo/main.py index c535419..85807c8 100644 --- a/demoapp/cliffdemo/main.py +++ b/demoapp/cliffdemo/main.py @@ -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): diff --git a/docs/source/history.rst b/docs/source/history.rst index eeaa92a..9e0f770 100644 --- a/docs/source/history.rst +++ b/docs/source/history.rst @@ -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 diff --git a/tests/test_app.py b/tests/test_app.py index cae2c32..8bff071 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -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(): -- cgit v1.2.1