From 1a444004dddbd534a40fb0b1fd6ee72d3c8deea9 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Thu, 21 Jul 2011 12:21:17 +1000 Subject: samba-tool: Raise exception on errors and report using base class Exceptions are captured at top-level samba-tool and reported using the base class (Command) method show_command_error(). Signed-off-by: Andrew Tridgell --- source4/scripting/python/samba/netcmd/__init__.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'source4') diff --git a/source4/scripting/python/samba/netcmd/__init__.py b/source4/scripting/python/samba/netcmd/__init__.py index 316a819053..3d1283048c 100644 --- a/source4/scripting/python/samba/netcmd/__init__.py +++ b/source4/scripting/python/samba/netcmd/__init__.py @@ -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 (-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: -- cgit