]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
samba-tool: avoid traceback for options errors
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Thu, 1 Sep 2022 03:32:07 +0000 (15:32 +1200)
committerDouglas Bagnall <dbagnall@samba.org>
Tue, 6 Sep 2022 21:12:36 +0000 (21:12 +0000)
What option? None yet, but see the next two commits.

We use a local reference to optparse.OptionValueError, to save typing
and make the eventual switch to argparse easier.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/getopt.py
python/samba/netcmd/__init__.py

index a271cd8a7369f02b768f594e7b28b7e913d130d8..4e70998d9d9b53038a59b8b0ae22aaebaa453c18 100644 (file)
@@ -31,6 +31,9 @@ from samba.credentials import (
 import sys
 
 
+OptionError = optparse.OptionValueError
+
+
 class SambaOptions(optparse.OptionGroup):
     """General Samba-related command line options."""
 
index 40b9b213f7018663b01d70433f9634b031ea0506..b98f8a47fd09a274a674e4f7f17fb407bec6138a 100644 (file)
@@ -19,7 +19,7 @@
 import optparse
 import samba
 from samba import colour
-from samba.getopt import SambaOption
+from samba.getopt import SambaOption, OptionError
 from samba.logger import get_samba_logger
 from ldb import LdbError, ERR_INVALID_CREDENTIALS
 import sys
@@ -110,7 +110,12 @@ class Command(object):
             message = "uncaught exception"
             force_traceback = True
 
-        if isinstance(inner_exception, LdbError):
+        if isinstance(e, OptionError):
+            print(evalue, file=self.errf)
+            self.usage()
+            force_traceback = False
+
+        elif isinstance(inner_exception, LdbError):
             (ldb_ecode, ldb_emsg) = inner_exception.args
             if ldb_ecode == ERR_INVALID_CREDENTIALS:
                 print("Invalid username or password", file=self.errf)