Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend \b rewrapping to click options #106

Closed
marekvi95 opened this issue Jun 16, 2022 · 2 comments
Closed

Extend \b rewrapping to click options #106

marekvi95 opened this issue Jun 16, 2022 · 2 comments

Comments

@marekvi95
Copy link

marekvi95 commented Jun 16, 2022

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
Copy link
Member

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

@marekvi95
Copy link
Author

marekvi95 commented Jun 20, 2022

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)
""",
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants