def format_help(self, formatter=None): class Positional(object): def __init__(self, args): self.option_groups = [] self.option_list = args positional = Positional(self.positional) formatter = IndentedHelpFormatter() formatter.store_option_strings(positional) output = ['\n', formatter.format_heading("Positional Arguments")] formatter.indent() pos_help = [formatter.format_option(opt) for opt in self.positional] pos_help = [line.replace('--','') for line in pos_help] output += pos_help return OptionParser.format_help(self, formatter) + ''.join(output)
def format_help(self, formatter=None): class Positional(object): def __init__(self, args): self.option_groups = [] self.option_list = args positional = Positional(self.positional) formatter = IndentedHelpFormatter() formatter.store_option_strings(positional) output = ['\n', formatter.format_heading("Positional Arguments")] formatter.indent() pos_help = [formatter.format_option(opt) for opt in self.positional] pos_help = [line.replace('--', '') for line in pos_help] output += pos_help return OptionParser.format_help(self, formatter) + ''.join(output)
def format_option(self, option): """Return colorful formatted help for an option.""" option = IndentedHelpFormatter.format_option(self, option) # long options with args option = re.sub( r"--([a-zA-Z]*)=([a-zA-Z]*)", lambda m: "-%s %s" % (output.green(m.group(1)), output.blue(m.group(2))), option) # short options with args option = re.sub( r"-([a-zA-Z]) ?([0-9A-Z]+)", lambda m: " -" + output.green( m.group(1)) + ' ' + output.blue(m.group(2)), option) # options without args option = re.sub(r"-([a-zA-Z?]+)", lambda m: "-" + output.green(m.group(1)), option) return option
def format_help(self, formatter=None): """ Create a help text based on the options defined. The -- that is added to the options is automatically removed """ class Positional(object): def __init__(self, args): self.option_groups = [] self.option_list = args positional = Positional(self.positional) formatter = IndentedHelpFormatter() formatter.store_option_strings(positional) output = ['\n', formatter.format_heading("Commands")] formatter.indent() pos_help = [formatter.format_option(opt) for opt in self.positional] pos_help = [line.replace('--', '') for line in pos_help] output += pos_help return OptionGroup.format_help(self, formatter) + ''.join(output)
def format_option(self, option): """Extend option formatting to include formatting of supported options.""" result = IndentedHelpFormatter.format_option(self, option) if option.action == 'command' and option.options: options = ', '.join(option.options) msg = _('Supported options: ') # build the complete options string and wrap it to width of the # help opt_str = ''.join((msg, options)) initial_indent = ' '*(self.help_position + 4) subsequent_indent = ' '*(self.help_position + 4 + len(msg)) width = self.help_position + self.help_width opt_str = textwrap.fill(opt_str, width, initial_indent=initial_indent, subsequent_indent=subsequent_indent) result += opt_str + '\n' return result
def format_option(self, option): """Return colorful formatted help for an option.""" option = IndentedHelpFormatter.format_option(self, option) # long options with args option = re.sub( r"--([a-zA-Z]*)=([a-zA-Z]*)", lambda m: "-%s %s" % (self.output.green(m.group(1)), self.output.blue(m.group(2))), option) # short options with args option = re.sub( r"-([a-zA-Z]) ?([0-9A-Z]+)", lambda m: " -" + self.output.green(m.group(1)) + ' ' + \ self.output.blue(m.group(2)), option) # options without args option = re.sub( r"-([a-zA-Z\d]+)", lambda m: "-" + self.output.green(m.group(1)), option) return option
def format_option(self, option): """Extend option formatting to include formatting of supported options.""" result = IndentedHelpFormatter.format_option(self, option) if option.action == 'command' and option.options: options = ', '.join(option.options) msg = _('Supported options: ') # make sure we have the correct length # (and are not counting unicode double-bytes twice, which would # break length calculation e.g. for german umlauts msg_len = len(msg.decode(_STDOUT_ENCODING)) # build the complete options string and wrap it to width of the # help opt_str = ''.join([msg, options]) initial_indent = ' '*(self.help_position + 4) subsequent_indent = ' '*(self.help_position + 4 + msg_len) width = self.help_position + self.help_width opt_str = textwrap.fill(opt_str, width, initial_indent=initial_indent, subsequent_indent=subsequent_indent) result += opt_str + '\n' return result
def format_option(self, text): textwrap.wrap, old = wrap_with_newlines, textwrap.wrap result = IndentedHelpFormatter.format_option(self, text) textwrap.wrap = old return result
def format_option(self, text): textwrap.wrap, old = wrap_with_newlines, textwrap.wrap result = IndentedHelpFormatter.format_option(self, text) textwrap.wrap = old return result