click-contrib / sphinx-click

A Sphinx plugin to automatically document click-based applications
MIT License
212 stars 57 forks source link

Extend \b rewrapping to click options #106

Closed marekvi95 closed 2 years ago

marekvi95 commented 2 years ago

We use \b to prevent rewrapping also in click options. There's a workaround in sphinx-click to append '|' when there's a line containing \b, but this workaround is missing for click.options and we receive warnings during sphinx build because of bad indentation. Please could you extend this also for click options?

Click 8.1.2 sphinx-click 4.1.0 Python 3.9.5

def _format_option(opt: click.Option) -> ty.Generator[str, None, None]:
    opt_help = _get_help_record(opt)

    yield ".. option:: {}".format(opt_help[0])
    if opt_help[1]:
        yield ""
        bar_enabled = False
        for line in statemachine.string2lines(
            ANSI_ESC_SEQ_RE.sub("", opt_help[1]), tab_width=4, convert_whitespace=True
        ):
            if line == "\b":
                bar_enabled = True
                continue
            if line == "":
                bar_enabled = False
            line = "| " + line if bar_enabled else line

            yield _indent(line)
stephenfin commented 2 years ago

Could you give me an example of a command with an option using \b (for test purposes)?

marekvi95 commented 2 years ago

We use this option with \b to prevent rewrapping

_lpcusbsio_option = click.option(
    "-l",
    "--lpcusbsio",
    metavar="[usb,VID:PID|USB_PATH|SER_NUM,]spi|i2c",
    help="""USB-SIO bridge interface.

    Optional USB device filtering formats:
    [usb,vid:pid|usb_path|serial_number]

    Following serial interfaces are supported:

    \b
    spi[index][,port,pin,speed_kHz,polarity,phase]
     - index ... optional index of SPI peripheral. Example: "spi1" (default=0)
     - port ... bridge GPIO port used as SPI SSEL(default=0)
     - pin  ... bridge GPIO pin used as SPI SSEL
        default SSEL is set to 0.15 which works
        for the LPCLink2 bridge. The MCULink OB
        bridge ignores the SSEL value anyway.(default=15)
     - speed_kHz ... SPI clock in kHz (default 1000)
     - polarity ... SPI CPOL option (default=1)
     - phase ... SPI CPHA option (default=1)

    \b
    i2c[index][,address,speed_kHz]
     - index ... optional index of I2C peripheral. Example: "i2c1" (default=0)
     - address ... I2C device address (default 0x10)
     - speed_kHz ... I2C clock in kHz (default 100)
""",
)