summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Hellmann <doug.hellmann@dreamhost.com>2012-05-10 14:58:18 -0400
committerDoug Hellmann <doug.hellmann@dreamhost.com>2012-05-10 14:58:18 -0400
commit921708980b2e7309f5c92831b467768370158714 (patch)
tree7279bc1557a48eb0bf5800c26b22c3af1235f2d7
parentdfe456fa6b6eadda8ba77fc74ad043e2b3f9d050 (diff)
downloadcliff-tablib-921708980b2e7309f5c92831b467768370158714.tar.gz
pass more details to initialize_app so subclasses can decide what sort of initialization to do
-rw-r--r--cliff/app.py7
-rw-r--r--demoapp/cliffdemo/main.py2
-rw-r--r--docs/source/history.rst5
-rw-r--r--tests/test_app.py2
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():