Utils Module

Utils for usage / help text formatters

author:

Doug Skrypa

cli_command_parser.formatting.utils.format_help_entry(usage_parts: StrIter, description: IStrs | None, prefix: str = '', *, lpad: int = 2, usage_cont_indent: int = 2, usage_delim: str = ', ') str[source]
Parameters:
  • usage_parts – Individual usage parts. That is, for an Option('--foo', '-f'), separate strings for '--foo FOO' and '-f FOO'.

  • description – The description (help='...' value) of the Parameter that is being documented.

  • prefix – A prefix to be included on every line (such as when show_group_tree=True).

  • lpad – Minimum indentation (number of spaces) that should be applied to each line as a prefix. If an explicit prefix is provided, then the padding will be reduced based on the length of the provided prefix.

  • usage_cont_indent – Continuation indentation to apply when the usage_parts need to span multiple lines.

  • usage_delim – The delimiter that should be used to join the usage_parts.

Returns:

The formatted --help entry.

class cli_command_parser.formatting.utils.PartWrapper(max_width: int = 30, cont_indent: int = 0, delim: str = ', ')[source]

Bases: object

max_width
cont_indent
delim
join(prefix: str, parts: StrIter) str[source]
format_help_entry(prefix: str, usage: StrIter, description: IStrs, usage_width: int, term_width: int) str[source]
combine_and_wrap(parts: StrIter) Iterator[str][source]

Combine the given strings using the given delimiter, wrapping to a new line at max_width.

cli_command_parser.formatting.utils.line_iter(*columns: IStrs) Iterator[list[str, ...]][source]

More complicated than what would be necessary for just 2 columns, but this will scale to handle 3+