onyo.main module

class onyo.main.OnyoArgumentParser(prog=None, usage=None, description=None, epilog=None, parents=[], formatter_class=<class 'argparse.HelpFormatter'>, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True, allow_abbrev=True, exit_on_error=True)[source]

Bases: ArgumentParser

Rich-ified ArgumentParser.

class onyo.main.OnyoRawTextHelpFormatter(prog, indent_increment=2, max_help_position=24, width=None)[source]

Bases: RawTextHelpFormatter

Fix the sins of argparse’s formatting; convert RST to Rich markup.

See also

argparse.ArgumentParser.RawTextHelpFormatter

start_section(heading)[source]

Start a section.

Just a wrapper to stylize headings for Rich.

Parameters:

heading (str | None) – Heading text.

Return type:

None

onyo.main.build_parser(parser, args)[source]

Add options or arguments to an ArgumentParser.

Parameters:
  • parser (ArgumentParser) – Parser to add arguments to.

  • args (dict) – Dictionary of option/argument dictionaries containing key-values to pass to ArgumentParser.add_argument(). The key name of the option/argument dictionary is passed as the value to dest.

Return type:

None

See also

ArgumentParser.add_argument

Example

An example option/argument dictionary:

args = {
    'debug': dict(
        args=('-d', '--debug'),
        required=False,
        default=False,
        action='store_true',
        help=r"Enable debug logging."
    ),
}
build_parser(parser, args)
onyo.main.get_subcmd_index(arglist, start=1)[source]

Get the index of the Onyo subcommand in a list of arguments.

Parameters:
  • arglist (list) – The list of command line arguments passed to a Python script. Usually sys.argv.

  • start (int (default: 1)) – The index to start searching from.

Return type:

int | None

Example

>>> subcmd_index = get_subcmd_index(sys.argv)
onyo.main.main()[source]

Execute Onyo’s CLI.

Return type:

None

onyo.main.rst_to_rich(text)[source]

Convert RST to Rich syntax.

Naively convert reStructuredText to Rich syntax, de-indent, and apply other cleanups to prepare text to print to the terminal.

Parameters:

text (str) – reStructuredText to convert.

Return type:

str

onyo.main.setup_parser()[source]

Return a fully populated OnyoArgumentParser for Onyo and all subcommands.

Return type:

OnyoArgumentParser