pg.py: handle command-less invocation cleanly
authorW. Trevor King <wking@tremily.us>
Tue, 11 Dec 2012 16:49:53 +0000 (11:49 -0500)
committerW. Trevor King <wking@tremily.us>
Tue, 11 Dec 2012 16:51:20 +0000 (11:51 -0500)
This avoids:

  Traceback (most recent call last):
    File "/.../pg.py", line 202, in <module>
      func_args = _inspect.getargspec(args.func).args
  AttributeError: 'Namespace' object has no attribute 'func'

bin/pg.py

index b8db60e..23f4d63 100755 (executable)
--- a/bin/pg.py
+++ b/bin/pg.py
@@ -178,6 +178,11 @@ if __name__ == '__main__':
 
     args = parser.parse_args()
 
+    if not hasattr(args, 'func'):
+        # no command selected; print help and die
+        parser.print_help()
+        _sys.exit(0)
+
     if args.verbose:
         _LOG.setLevel(max(_logging.DEBUG, _LOG.level - 10*args.verbose))
         _pgp_mime.LOG.setLevel(_LOG.level)