Repository: click-contrib/sphinx-click

Issue:
Display `show_default` string even when `default=None`
# Current behavior

The option

```python
@click.option('--foo', show_default='mydefault')
```

will not have a default documented

# Expected behavior

The text `mydefault` is documented as the default value for this option.

# What now?

Looking at the code [here](https://github.com/click-contrib/sphinx-click/blob/6aeee375067483337b5cfda98233d4fb1a1addb1/sphinx_click/ext.py#L76), the fix seems relatively straightforward.

I'd like to submit a PR if you agree :)


Discussion:
stephenfin: Could you fix the failing lint job (run `tox -e pep8` locally) and I'll merge this
ariebovenberg: @stephenfin done.

Patch:
diff --git a/sphinx_click/ext.py b/sphinx_click/ext.py
index be645ab..4441588 100644
--- a/sphinx_click/ext.py
+++ b/sphinx_click/ext.py
@@ -73,21 +73,20 @@ def _get_help_record(opt):
 
     extras = []
 
-    if opt.default is not None and opt.show_default:
-        if isinstance(opt.show_default, str):
-            # Starting from Click 7.0 this can be a string as well. This is
-            # mostly useful when the default is not a constant and
-            # documentation thus needs a manually written string.
-            extras.append(':default: %s' % opt.show_default)
-        else:
-            extras.append(
-                ':default: %s'
-                % (
-                    ', '.join(str(d) for d in opt.default)
-                    if isinstance(opt.default, (list, tuple))
-                    else opt.default,
-                )
+    if isinstance(opt.show_default, str):
+        # Starting from Click 7.0 show_default can be a string. This is
+        # mostly useful when the default is not a constant and
+        # documentation thus needs a manually written string.
+        extras.append(':default: %s' % opt.show_default)
+    elif opt.default is not None and opt.show_default:
+        extras.append(
+            ':default: %s'
+            % (
+                ', '.join(str(d) for d in opt.default)
+                if isinstance(opt.default, (list, tuple))
+                else opt.default,
             )
+        )
 
     if isinstance(opt.type, click.Choice):
         extras.append(':options: %s' % ' | '.join(str(x) for x in opt.type.choices))


Test patch:
diff --git a/tests/test_formatter.py b/tests/test_formatter.py
index 3a959d9..0cc8651 100644
--- a/tests/test_formatter.py
+++ b/tests/test_formatter.py
@@ -177,6 +177,10 @@ class CommandTestCase(unittest.TestCase):
             multiple=True,
             show_default=True,
         )
+        @click.option(
+            '--only-show-default',
+            show_default="Some default computed at runtime!",
+        )
         def foobar(bar):
             """A sample command."""
             pass
@@ -207,6 +211,10 @@ class CommandTestCase(unittest.TestCase):
         .. option:: --group <group>
 
             :default: ('foo', 'bar')
+
+        .. option:: --only-show-default <only_show_default>
+
+            :default: Some default computed at runtime!
         """
             ).lstrip(),
             '\n'.join(output),