summaryrefslogtreecommitdiff
path: root/demoapp
diff options
context:
space:
mode:
authorDoug Hellmann <doug.hellmann@gmail.com>2012-04-22 15:14:02 -0700
committerDoug Hellmann <doug.hellmann@gmail.com>2012-04-22 15:14:02 -0700
commit276e8a4694575d15bf6c722f758343d4ca635495 (patch)
tree8c71e20c939648bb87af8212cfa866268882556d /demoapp
parentc842a1bfce909240fa40d7e7a79b1f31bfa464a8 (diff)
downloadcliff-276e8a4694575d15bf6c722f758343d4ca635495.tar.gz
add some error handling to App
Diffstat (limited to 'demoapp')
-rw-r--r--demoapp/cliffdemo/main.py8
-rw-r--r--demoapp/cliffdemo/simple.py10
-rw-r--r--demoapp/setup.py1
3 files changed, 16 insertions, 3 deletions
diff --git a/demoapp/cliffdemo/main.py b/demoapp/cliffdemo/main.py
index cebf552..9059227 100644
--- a/demoapp/cliffdemo/main.py
+++ b/demoapp/cliffdemo/main.py
@@ -19,14 +19,16 @@ class DemoApp(App):
def prepare_to_run_command(self, cmd):
self.log.debug('prepare_to_run_command %s', cmd.__class__.__name__)
- def clean_up(self, cmd, result):
+ def clean_up(self, cmd, result, err):
self.log.debug('clean_up %s', cmd.__class__.__name__)
+ if err:
+ self.log.debug('got an error: %s', err)
def main(argv=sys.argv[1:]):
myapp = DemoApp()
- myapp.run(argv)
+ return myapp.run(argv)
if __name__ == '__main__':
- main(sys.argv[1:])
+ sys.exit(main(sys.argv[1:]))
diff --git a/demoapp/cliffdemo/simple.py b/demoapp/cliffdemo/simple.py
index 2f273b9..1d449d0 100644
--- a/demoapp/cliffdemo/simple.py
+++ b/demoapp/cliffdemo/simple.py
@@ -12,3 +12,13 @@ class Simple(Command):
self.log.info('sending greeting')
self.log.debug('debugging')
print('hi!')
+
+
+class Error(Command):
+ "Always raises an error"
+
+ log = logging.getLogger(__name__)
+
+ def run(self, parsed_args):
+ self.log.info('causing error')
+ raise RuntimeError('this is the expected exception')
diff --git a/demoapp/setup.py b/demoapp/setup.py
index ec3dcec..fea934c 100644
--- a/demoapp/setup.py
+++ b/demoapp/setup.py
@@ -163,6 +163,7 @@ setup(
'cliff.demo': [
'simple = cliffdemo.simple:Simple',
'two_part = cliffdemo.simple:Simple',
+ 'error = cliffdemo.simple:Error',
],
# 'virtualenvwrapper.initialize': [
# 'user_scripts = virtualenvwrapper.user_scripts:initialize',