def print_doc(cls, docs, stream=None, short=False, long=False): if stream is None: stream = sys.stdout docs = [doc for doc in docs if doc[2]] if not docs: return if short: max_len = max(len(doc[0]) for doc in docs) for cmd, args, doc in docs: paragraphs = cls.split_help_text(doc) console_print(stream, '%s %s' % (cmd.ljust(max_len), paragraphs[0])) else: for cmd, args, doc in docs: paragraphs = cls.split_help_text(doc) console_print(stream, '%s %s\n' % (cmd, args)) console_print(stream, ' %s\n' % paragraphs[0]) if (long or len(docs) == 1) and len(paragraphs) > 1: for paragraph in paragraphs[1:]: console_print( stream, textwrap.fill(paragraph, 79, initial_indent=' ', subsequent_indent=' ') + '\n')
def parse_help_text(self, file_path): ''' Load of list of commands and descriptions from a file. ''' with open(file_path) as f: lines = f.readlines() # Parse commands and descriptions, which are separated by a multi-space # (any sequence of two or more space characters in a row. cmds = [] descs = [] for line in lines: line = line.strip() if len(line) == 0: cmds.append('') descs.append('') else: tokens = line.split(' ') cmds.append(tokens[0]) descs.append(''.join(tokens[1:]).strip()) max_len = len(max(cmds, key=len)) # Convert commands and descriptions into help text. text = '' for cmd, desc in zip(cmds, descs): if len(cmd) == 0: text += '\n' else: text += self.style.help(cmd.ljust(max_len + 2), desc + '\n') return cmds, text
def print_topics(self,header,cmds,cmdlen,maxcol): if cmds: self.stdout.write("%s\n"%(str(header))) if self.ruler:self.stdout.write("%s\n"%(str(self.ruler * len(header)))) for cmd in cmds: self.stdout.write("%s %s\n"%(cmd.ljust(15),getattr(self,"do_"+cmd).__doc__)) self.stdout.write("\n")
def print_topics(self, header, cmds, cmdlen, maxcol): if cmds: self.stdout.write("%s\n"%str(header)) if self.ruler: self.stdout.write("%s\n"%str(self.ruler * len(header))) for cmd in cmds: self.stdout.write("%s %s\n" % (cmd.ljust(15), getattr(self, 'do_' + cmd).__doc__)) self.stdout.write("\n")
def print_topics(self, header, cmds, cmdlen, maxcol): """make help menu more readable""" if cmds: self.stdout.write("%s\n" % str(header)) if self.ruler: self.stdout.write("%s\n" % str(self.ruler * len(header))) for cmd in cmds: help_msg = getattr(self, "do_%s" % cmd).__doc__ self.stdout.write("%s%s\n" % (cmd.ljust(16), help_msg)) self.stdout.write("\n")
def print_doc(cls, docs, stream=None, short=False, long=False): if stream is None: stream = sys.stdout docs = [doc for doc in docs if doc[2]] if not docs: return if short: max_len = max(len(doc[0]) for doc in docs) for (cmd, args, doc) in docs: paragraphs = cls.split_help_text(doc) console_print(stream, '%s %s' % (cmd.ljust(max_len), paragraphs[0])) else: import textwrap for (cmd, args, doc) in docs: paragraphs = cls.split_help_text(doc) console_print(stream, '%s %s\n' % (cmd, args)) console_print(stream, ' %s\n' % paragraphs[0]) if (long or len(docs) == 1) and len(paragraphs) > 1: for paragraph in paragraphs[1:]: console_print(stream, textwrap.fill(paragraph, 79, initial_indent=' ', subsequent_indent=' ') + '\n')