# 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
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):
synopsis = None
takes_args = []
takes_options = []
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "credopts": options.CredentialsOptions,
- "versionopts": options.VersionOptions,
- }
- outf = sys.stdout
- errf = sys.stderr
+ takes_optiongroups = {}
+
+ def __init__(self, outf=sys.stdout, errf=sys.stderr):
+ self.outf = outf
+ self.errf = errf
def usage(self, prog, *args):
parser, _ = self._create_parser(prog)
parser = optparse.OptionParser(
usage=self.synopsis,
description=self.full_description,
+ formatter=PlainHelpFormatter(),
prog=prog)
parser.add_options(self.takes_options)
optiongroups = {}
class SuperCommand(Command):
"""A samba-tool command with subcommands."""
+ synopsis = "%prog <subcommand>"
+
subcommands = {}
def _run(self, myname, subcommand=None, *args):