>From 01ae0c7e6ad981bf1ed72a05c7918b31e665e7b4 Mon Sep 17 00:00:00 2001
From: Theresa Halloran <thallora@linux.vnet.ibm.com>
Date: Wed, 19 Oct 2011 21:45:17 -0400
Subject: [PATCH] s4: samba-tool --help enhancements Signed-off-by: Theresa
 Halloran <thallora@linux.vnet.ibm.com>

---
 source4/scripting/python/samba/netcmd/__init__.py |   15 +++++++++++++++
 source4/scripting/python/samba/netcmd/user.py     |   19 ++++++++++++++++++-
 2 files changed, 33 insertions(+), 1 deletions(-)

diff --git a/source4/scripting/python/samba/netcmd/__init__.py b/source4/scripting/python/samba/netcmd/__init__.py
index bf08457..c48aceb 100644
--- a/source4/scripting/python/samba/netcmd/__init__.py
+++ b/source4/scripting/python/samba/netcmd/__init__.py
@@ -30,6 +30,20 @@ class Option(optparse.Option):
     pass
 
 
+# This help formatter does text wrapping and preserves newlines
+class PlainHelpFormatter(optparse.IndentedHelpFormatter):
+    def format_description(self,description=""):
+            desc_width = self.width - self.current_indent
+            indent = " "*self.current_indent
+            paragraphs = description.split('\n')
+            wrapped_paragraphs = [
+                textwrap.fill(p,
+                        desc_width,
+                        initial_indent=indent,
+                        subsequent_indent=indent)
+                for p in paragraphs]
+            result = "\n".join(wrapped_paragraphs) + "\n"
+            return result
 
 class Command(object):
     """A samba-tool command."""
@@ -107,6 +121,7 @@ class Command(object):
         parser = optparse.OptionParser(
             usage=self.synopsis,
             description=self.full_description,
+            formatter=PlainHelpFormatter(),
             prog=prog)
         parser.add_options(self.takes_options)
         optiongroups = {}
diff --git a/source4/scripting/python/samba/netcmd/user.py b/source4/scripting/python/samba/netcmd/user.py
index cbac5af..74858bf 100644
--- a/source4/scripting/python/samba/netcmd/user.py
+++ b/source4/scripting/python/samba/netcmd/user.py
@@ -37,7 +37,24 @@ from samba.netcmd import (
 
 
 class cmd_user_add(Command):
-    """Creates a new user"""
+    """Creates a new user
+This command creates a new user account in the Active Directory domain.  The username specified on the command is the sAMaccountname.
+
+User accounts may represent physical entities, such as people or may be used as service accounts for applications.  User accounts are also referred to as security principals and are assigned a security identifier (SID).
+
+A user account enables a user to logon to a computer and domain with an identity that can be authenticated.  To maximize security, each user should have their own unique user account and password.  A user's access to domain resources is based on permissions assigned to the user account.
+
+The command may be run from the root userid or another authorized userid.
+
+Example1:
+samba-tool user create User1 passw0rd --given-name=John --surname=Smith --must-change-at-next-login -H ldap://samba.samdom.example.com -Uadministrator%passw1rd
+
+Example1 shows how to create a new user in the domain against a remote LDAP server.  The -U option is used to pass the userid and password authorized to issue the command remotely.
+
+Example2:
+sudo samba-tool user create User2 passw2rd --given-name=Jane --surname=Doe --must-change-at-next-login
+
+Example2 shows how to create a new user in the domain against the local server.   sudo is used so a user may run the command as root."""
 
     synopsis = "%prog <username> [<password>] [options]"
 
-- 
1.7.6.4

