Revert "samba-tool: moved takes_optiongroups definition to Command base class"
[tridge/samba.git] / source4 / scripting / python / samba / netcmd / __init__.py
index 58353a07f4686a3c20d411814f205d056d76a959..f0cf7809c2994413260fb4c607249f7d029337cc 100644 (file)
@@ -3,7 +3,6 @@
 # Unix SMB/CIFS implementation.
 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2009-2011
 # Copyright (C) Theresa Halloran <theresahalloran@gmail.com> 2011
-# Copyright (C) Giampaolo Lauria <lauria2@yahoo.com> 2011
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -25,10 +24,24 @@ from ldb import LdbError
 import sys, traceback
 import textwrap
 
-
 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."""
@@ -57,11 +70,7 @@ class Command(object):
     synopsis = None
     takes_args = []
     takes_options = []
-    takes_optiongroups = {
-        "sambaopts": options.SambaOptions,
-        "credopts": options.CredentialsOptions,
-        "versionopts": options.VersionOptions,
-        }
+    takes_optiongroups = {}
 
     def __init__(self, outf=sys.stdout, errf=sys.stderr):
         self.outf = outf
@@ -108,6 +117,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 = {}