otx.cli.utils.help_formatter#

Custom Help Formatters for OTX CLI.

Functions

get_cli_usage_docstring(component)

Get the cli usage from the docstring.

get_verbosity_subcommand()

Parse command line arguments and returns a dictionary of key-value pairs.

render_guide([subcommand])

Render a guide for the specified subcommand.

Classes

CustomHelpFormatter(prog[, ...])

A custom help formatter for OTX CLI.

class otx.cli.utils.help_formatter.CustomHelpFormatter(prog: str, indent_increment: int = 2, max_help_position: int = 24, width: int | None = None, console: Console | None = None)[source]#

Bases: RichHelpFormatter, DefaultHelpFormatter

A custom help formatter for OTX CLI.

This formatter extends the RichHelpFormatter and DefaultHelpFormatter classes to provide a more detailed and customizable help output for OTX CLI.

verbosity_level#

int The level of verbosity for the help output.

subcommand#

str | None The subcommand to render the guide for.

add_usage(usage, actions, *args, **kwargs)[source]#

Add usage information to the help output.

add_argument(action)[source]#

Add an argument to the help output.

format_help()[source]#

Format the help output.

add_argument(action: argparse.Action) None[source]#

Add an argument to the help formatter.

If the verbose level is set to 0, the argument is not added. If the verbose level is set to 1 and the argument is not in the non-skip list, the argument is not added.

Parameters:

action (argparse.Action) – The action to add to the help formatter.

add_usage(usage: str | None, actions: Iterable[argparse.Action], *args, **kwargs) None[source]#

Add usage information to the formatter.

Parameters:
  • usage (str | None) – A string describing the usage of the program.

  • actions (Iterable[argparse.Action]) – An list of argparse.Action objects.

  • *args (Any) – Additional positional arguments to pass to the superclass method.

  • **kwargs (Any) – Additional keyword arguments to pass to the superclass method.

Returns:

None

format_help() str[source]#

Format the help message for the current command and returns it as a string.

The help message includes information about the command’s arguments and options, as well as any additional information provided by the command’s help guide.

Returns:

A string containing the formatted help message.

Return type:

str

otx.cli.utils.help_formatter.get_cli_usage_docstring(component: object | None) str | None[source]#

Get the cli usage from the docstring.

Parameters:

component (Optional[object]) – The component to get the docstring from

Returns:

The quick-start guide as Markdown format.

Return type:

Optional[str]

Example

component.__doc__ = ‘’’

<Prev Section>

CLI Usage:
  1. First Step.

  2. Second Step.

<Next Section>

‘’’ >>> get_cli_usage_docstring(component) “1. First Step.n2. Second Step.”

otx.cli.utils.help_formatter.get_verbosity_subcommand() dict[source]#

Parse command line arguments and returns a dictionary of key-value pairs.

Returns:

A dictionary containing the parsed command line arguments.

Examples

>>> import sys
>>> sys.argv = ['otx', 'train', '-h', '-v']
>>> get_verbosity_subcommand()
{'subcommand': 'train', 'help': True, 'verbosity': 1}
otx.cli.utils.help_formatter.render_guide(subcommand: str | None = None) list[source]#

Render a guide for the specified subcommand.

Parameters:

subcommand (Optional[str]) – The subcommand to render the guide for.

Returns:

A list of contents to be displayed in the guide.

Return type:

list