diff options
-rw-r--r-- | .travis.yml | 6 | ||||
-rw-r--r-- | README.rst | 2 | ||||
-rw-r--r-- | cliff/app.py | 26 | ||||
-rw-r--r-- | demoapp/cliffdemo/main.py | 2 | ||||
-rw-r--r-- | docs/source/conf.py | 2 | ||||
-rw-r--r-- | docs/source/developers.rst | 2 | ||||
-rw-r--r-- | docs/source/history.rst | 5 | ||||
-rw-r--r-- | setup.py | 2 | ||||
-rw-r--r-- | test-requirements.txt | 8 | ||||
-rw-r--r-- | tests/test_app.py | 2 |
10 files changed, 46 insertions, 11 deletions
diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..eb4857e --- /dev/null +++ b/.travis.yml @@ -0,0 +1,6 @@ +language: python +python: + - 2.7 + - 3.2 +install: pip install -r test-requirements.txt +script: nosetests -d
\ No newline at end of file @@ -2,6 +2,8 @@ cliff -- Command Line Interface Formulation Framework ======================================================= +.. image:: https://secure.travis-ci.org/dhellmann/cliff.png?branch=master + cliff is a framework for building command line programs. It uses setuptools entry points to provide subcommands, output formatters, and other extensions. diff --git a/cliff/app.py b/cliff/app.py index d202a7f..2b60d34 100644 --- a/cliff/app.py +++ b/cliff/app.py @@ -135,11 +135,20 @@ class App(object): :param argv: input arguments and options :paramtype argv: list of str """ - self.options, remainder = self.parser.parse_known_args(argv) - self.configure_logging() - self.initialize_app() + try: + self.options, remainder = self.parser.parse_known_args(argv) + self.configure_logging() + self.interactive_mode = not remainder + self.initialize_app(remainder) + except Exception as err: + if self.options.debug: + LOG.exception(err) + raise + else: + LOG.error(err) + return 1 result = 1 - if not remainder: + if self.interactive_mode: result = self.interact() else: result = self.run_subcommand(remainder) @@ -147,10 +156,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 @@ -175,7 +187,6 @@ class App(object): return def interact(self): - self.interactive_mode = True interpreter = self.interactive_app_factory(self, self.command_manager, self.stdin, self.stdout) interpreter.cmdloop() return 0 @@ -192,9 +203,10 @@ class App(object): parsed_args = cmd_parser.parse_args(sub_argv) result = cmd.run(parsed_args) except Exception as err: - LOG.error('ERROR: %s', err) if self.options.debug: LOG.exception(err) + else: + LOG.error(err) try: self.clean_up(cmd, result, err) except Exception as err2: 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/conf.py b/docs/source/conf.py index cfcbf28..8b87537 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -48,7 +48,7 @@ copyright = u'2012, Doug Hellmann' # built documents. # # The short X.Y version. -version = '0.5.1' +version = '0.6' # The full version, including alpha/beta/rc tags. release = version diff --git a/docs/source/developers.rst b/docs/source/developers.rst index f066a49..46b9808 100644 --- a/docs/source/developers.rst +++ b/docs/source/developers.rst @@ -56,6 +56,8 @@ The output version of the documentation ends up in Running Tests ============= +.. image:: https://secure.travis-ci.org/dhellmann/cliff.png?branch=master + The test suite for clif uses tox_, which must be installed separately (``pip install tox``). diff --git a/docs/source/history.rst b/docs/source/history.rst index eeaa92a..0459c20 100644 --- a/docs/source/history.rst +++ b/docs/source/history.rst @@ -2,6 +2,11 @@ Release History ================= +0.6 + + - 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 @@ -3,7 +3,7 @@ PROJECT = 'cliff' # Change docs/source/conf.py too! -VERSION = '0.5.1' +VERSION = '0.6' # Bootstrap installation of Distribute import distribute_setup diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..9a04558 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,8 @@ +nose +mock +coverage +pep8 +cmd2 +distribute +PrettyTable +tablib 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(): |