samba-tool: Raise exception on errors and report using base class
authorAmitay Isaacs <amitay@gmail.com>
Thu, 21 Jul 2011 02:21:17 +0000 (12:21 +1000)
committerAndrew Tridgell <tridge@samba.org>
Thu, 28 Jul 2011 05:20:52 +0000 (15:20 +1000)
Exceptions are captured at top-level samba-tool and reported using
the base class (Command) method show_command_error().

Signed-off-by: Andrew Tridgell <tridge@samba.org>
source4/scripting/python/samba/netcmd/__init__.py

index 316a819053cd851c8b5ca52c830dbb701c4d9a02..3d1283048c359b52d18e5de9cc7550a81d461347 100644 (file)
@@ -164,18 +164,11 @@ class SuperCommand(Command):
         for cmd in subcmds:
             print "    %-20s - %s" % (cmd, self.subcommands[cmd].description)
         if subcommand in [None]:
-            self.show_command_error("You must specify a subcommand")
-            return -1
-        if subcommand in ['-h', '--help']:
+            raise CommandError("You must specify a subcommand")
+        if subcommand in ['help', '-h', '--help']:
             print "For more help on a specific subcommand, please type: samba-tool %s <subcommand> (-h|--help)" % myname
             return 0
-        self.show_command_error("No such subcommand '%s'" % (subcommand))
-
-    def show_command_error(self, msg):
-        '''display a command error'''
-
-        print >>sys.stderr, "ERROR: %s" % (msg)
-        sys.exit(1)
+        raise CommandError("No such subcommand '%s'" % subcommand)
 
     def usage(self, myname, subcommand=None, *args):
         if subcommand is None or not subcommand in self.subcommands: