From e8b15c82539d6203475d195ac963b78bae6118a5 Mon Sep 17 00:00:00 2001
From: Antoine Lambert <anlambert@softwareheritage.org>
Date: Thu, 28 Mar 2024 15:22:18 +0100
Subject: [PATCH] cli: Prevent YAML wrapping in help displayed by Click

The default behavior of Click is to rewrap text based on the width of
the terminal but as a consequence it makes the sample YAML config for
the scrubber displayed in command help quite unreadable as indentation
is lost.

So use \b markers in docstring to ensure proper display of the YAML
config by Click.
---
 swh/scrubber/cli.py | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/swh/scrubber/cli.py b/swh/scrubber/cli.py
index 2347a2c..78b4568 100644
--- a/swh/scrubber/cli.py
+++ b/swh/scrubber/cli.py
@@ -14,6 +14,17 @@ from swh.core.cli import swh as swh_cli_group
 from swh.model.swhids import ObjectType
 
 
+def _fix_sphinx_docstring():
+    """Remove \b markers used by click to prevent text rewrapping in docstring."""
+
+    def decorator(f):
+        if "SWH_DOC_BUILD" in os.environ:
+            f.__doc__ = f.__doc__.replace("\b", "")
+        return f
+
+    return decorator
+
+
 @swh_cli_group.group(name="scrubber", context_settings=CONTEXT_SETTINGS)
 @click.option(
     "--config-file",
@@ -26,15 +37,17 @@ from swh.model.swhids import ObjectType
     help="Configuration file.",
 )
 @click.pass_context
+@_fix_sphinx_docstring()
 def scrubber_cli_group(ctx, config_file: Optional[str]) -> None:
     """main command group of the datastore scrubber
 
+    \b
     Expected config format::
-
+        \b
         scrubber:
             cls: postgresql
             db: "service=..."    # libpq DSN
-
+        \b
         # for storage checkers + origin locator only:
         storage:
             cls: postgresql     # cannot be remote for checkers, as they need direct
@@ -42,7 +55,7 @@ def scrubber_cli_group(ctx, config_file: Optional[str]) -> None:
             db": "service=..."  # libpq DSN
             objstorage:
                 cls: memory
-
+        \b
         # for journal checkers only:
         journal:
             # see https://docs.softwareheritage.org/devel/apidoc/swh.journal.client.html
-- 
GitLab