MCPcopy Index your code
hub / github.com/RustPython/RustPython / _format_usage

Method _format_usage

Lib/argparse.py:317–405  ·  view source on GitHub ↗
(self, usage, actions, groups, prefix)

Source from the content-addressed store, hash-verified

315 if part and part is not SUPPRESS])
316
317 def _format_usage(self, usage, actions, groups, prefix):
318 t = self._theme
319
320 if prefix is None:
321 prefix = _('usage: ')
322
323 # if usage is specified, use that
324 if usage is not None:
325 usage = (
326 t.prog_extra
327 + usage
328 % {"prog": f"{t.prog}{self._prog}{t.reset}{t.prog_extra}"}
329 + t.reset
330 )
331
332 # if no optionals or positionals are available, usage is just prog
333 elif usage is None and not actions:
334 usage = f"{t.prog}{self._prog}{t.reset}"
335
336 # if optionals and positionals are available, calculate usage
337 elif usage is None:
338 prog = '%(prog)s' % dict(prog=self._prog)
339
340 parts, pos_start = self._get_actions_usage_parts(actions, groups)
341 # build full usage string
342 usage = ' '.join(filter(None, [prog, *parts]))
343
344 # wrap the usage parts if it's too long
345 text_width = self._width - self._current_indent
346 if len(prefix) + len(self._decolor(usage)) > text_width:
347
348 # break usage into wrappable parts
349 opt_parts = parts[:pos_start]
350 pos_parts = parts[pos_start:]
351
352 # helper for wrapping lines
353 def get_lines(parts, indent, prefix=None):
354 lines = []
355 line = []
356 indent_length = len(indent)
357 if prefix is not None:
358 line_len = len(prefix) - 1
359 else:
360 line_len = indent_length - 1
361 for part in parts:
362 part_len = len(self._decolor(part))
363 if line_len + 1 + part_len > text_width and line:
364 lines.append(indent + ' '.join(line))
365 line = []
366 line_len = indent_length - 1
367 line.append(part)
368 line_len += part_len + 1
369 if line:
370 lines.append(indent + ' '.join(line))
371 if prefix is not None:
372 lines[0] = lines[0][indent_length:]
373 return lines
374

Callers

nothing calls this directly

Calls 8

filterFunction · 0.85
lenFunction · 0.85
get_linesFunction · 0.85
_Function · 0.50
joinMethod · 0.45
extendMethod · 0.45
removeprefixMethod · 0.45

Tested by

no test coverage detected