MCPcopy Index your code
hub / github.com/python/cpython / format_option

Method format_option

Lib/optparse.py:283–317  ·  view source on GitHub ↗
(self, option)

Source from the content-addressed store, hash-verified

281 return option.help.replace(self.default_tag, str(default_value))
282
283 def format_option(self, option):
284 # The help for each option consists of two parts:
285 # * the opt strings and metavars
286 # eg. ("-x", or "-fFILENAME, --file=FILENAME")
287 # * the user-supplied help string
288 # eg. ("turn on expert mode", "read data from FILENAME")
289 #
290 # If possible, we write both of these on the same line:
291 # -x turn on expert mode
292 #
293 # But if the opt string list is too long, we put the help
294 # string on a second line, indented to the same column it would
295 # start in if it fit on the first line.
296 # -fFILENAME, --file=FILENAME
297 # read data from FILENAME
298 result = []
299 opts = self.option_strings[option]
300 opt_width = self.help_position - self.current_indent - 2
301 if len(opts) > opt_width:
302 opts = "%*s%s\n" % (self.current_indent, "", opts)
303 indent_first = self.help_position
304 else: # start help on same line as opts
305 opts = "%*s%-*s " % (self.current_indent, "", opt_width, opts)
306 indent_first = 0
307 result.append(opts)
308 if option.help:
309 import textwrap
310 help_text = self.expand_default(option)
311 help_lines = textwrap.wrap(help_text, self.help_width)
312 result.append("%*s%s\n" % (indent_first, "", help_lines[0]))
313 result.extend(["%*s%s\n" % (self.help_position, "", line)
314 for line in help_lines[1:]])
315 elif opts[-1] != "\n":
316 result.append("\n")
317 return "".join(result)
318
319 def store_option_strings(self, parser):
320 self.indent()

Callers 1

format_option_helpMethod · 0.80

Calls 5

expand_defaultMethod · 0.95
appendMethod · 0.45
wrapMethod · 0.45
extendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected