r26628: python: Add more documentation, simplify code in Samba3 module.
[ab/samba.git/.git] / source4 / scripting / python / samba / getopt.py
index 8143dcafdb42f27cfd1f5d8c7a5e4869f6b5e19f..c0e70530626eec5e1003dc82503ff613fe160eed 100644 (file)
@@ -23,7 +23,7 @@ from credentials import Credentials
 class SambaOptions(optparse.OptionGroup):
     def __init__(self, parser):
         optparse.OptionGroup.__init__(self, parser, "Samba Common Options")
-        self.add_option("--configfile", type="string", metavar="FILE",
+        self.add_option("-s", "--configfile", type="string", metavar="FILE",
                         help="Configuration file")
 
 
@@ -35,12 +35,30 @@ class VersionOptions(optparse.OptionGroup):
 class CredentialsOptions(optparse.OptionGroup):
     def __init__(self, parser):
         optparse.OptionGroup.__init__(self, parser, "Credentials Options")
-        self.add_option("--simple-bind-dn", type="string", metavar="DN",
+        self.add_option("--simple-bind-dn", metavar="DN", action="callback",
+                        callback=self.set_simple_bind_dn, type=str,
                         help="DN to use for a simple bind")
-        self.add_option("--password", type="string", metavar="PASSWORD",
-                        help="Password")
+        self.add_option("--password", metavar="PASSWORD", action="callback",
+                        help="Password", type=str, callback=self.set_password)
+        self.add_option("-U", "--username", metavar="USERNAME", 
+                        action="callback", type=str,
+                        help="Username", callback=self.parse_username)
+        self.add_option("-W", "--workgroup", metavar="WORKGROUP", 
+                        action="callback", type=str,
+                        help="Workgroup", callback=self.parse_workgroup)
+        self.creds = Credentials()
+
+    def parse_username(self, option, opt_str, arg, parser):
+        self.creds.parse_string(arg)
+
+    def parse_workgroup(self, option, opt_str, arg, parser):
+        self.creds.set_domain(arg)
+
+    def set_password(self, option, opt_str, arg, parser):
+        self.creds.set_password(arg)
+
+    def set_simple_bind_dn(self, option, opt_str, arg, parser):
+        self.creds.set_bind_dn(arg)
 
     def get_credentials(self):
-        creds = Credentials()
-        # FIXME: Update
-        return creds
+        return self.creds