Patchwork D9988: gendoc: support defaults on customopts a bit better

login
register
mail settings
Submitter phabricator
Date Feb. 12, 2021, 8:05 p.m.
Message ID <differential-rev-PHID-DREV-suquqxwsv2s7vwu2grmv-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48303/
State Superseded
Headers show

Comments

phabricator - Feb. 12, 2021, 8:05 p.m.
spectral created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Without this, a customopt will very likely render like this:
  
    -foo   does foo (default: <hgext.myextension.MyOpt object at 0x7f31...>)
  
  I copied this logic from how this is handled in mercurial/help.py.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9988

AFFECTED FILES
  doc/gendoc.py

CHANGE DETAILS




To: spectral, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/doc/gendoc.py b/doc/gendoc.py
--- a/doc/gendoc.py
+++ b/doc/gendoc.py
@@ -31,6 +31,7 @@ 
     commands,
     encoding,
     extensions,
+    fancyopts,
     help,
     minirst,
     pycompat,
@@ -86,6 +87,8 @@ 
         if b'\n' in desc:
             # only remove line breaks and indentation
             desc = b' '.join(l.lstrip() for l in desc.split(b'\n'))
+        if isinstance(default, fancyopts.customopt):
+            default = default.getdefaultvalue()
         if default:
             default = stringutil.forcebytestr(default)
             desc += _(b" (default: %s)") % default