##// END OF EJS Templates
fancyopts: fix rendering of customopt defaults in help text...
Daniel Ploch -
r37109:979c8ce9 default
parent child Browse files
Show More
@@ -20,6 +20,7 b' from . import ('
20 encoding,
20 encoding,
21 error,
21 error,
22 extensions,
22 extensions,
23 fancyopts,
23 filemerge,
24 filemerge,
24 fileset,
25 fileset,
25 minirst,
26 minirst,
@@ -84,7 +85,10 b' def optrst(header, options, verbose):'
84 if shortopt:
85 if shortopt:
85 so = '-' + shortopt
86 so = '-' + shortopt
86 lo = '--' + longopt
87 lo = '--' + longopt
87 if default:
88
89 if isinstance(default, fancyopts.customopt):
90 default = default.defaultvalue
91 if default and not callable(default):
88 # default is of unknown type, and in Python 2 we abused
92 # default is of unknown type, and in Python 2 we abused
89 # the %s-shows-repr property to handle integers etc. To
93 # the %s-shows-repr property to handle integers etc. To
90 # match that behavior on Python 3, we do str(default) and
94 # match that behavior on Python 3, we do str(default) and
@@ -716,15 +716,23 b' this is a section and erroring out weird'
716
716
717 $ cat > helpext.py <<EOF
717 $ cat > helpext.py <<EOF
718 > import os
718 > import os
719 > from mercurial import commands, registrar
719 > from mercurial import commands, fancyopts, registrar
720 >
720 >
721 > def func(arg):
722 > return '%sfoo' % arg
723 > class customopt(fancyopts.customopt):
724 > def newstate(self, oldstate, newparam, abort):
725 > return '%sbar' % oldstate
721 > cmdtable = {}
726 > cmdtable = {}
722 > command = registrar.command(cmdtable)
727 > command = registrar.command(cmdtable)
723 >
728 >
724 > @command(b'nohelp',
729 > @command(b'nohelp',
725 > [(b'', b'longdesc', 3, b'x'*90),
730 > [(b'', b'longdesc', 3, b'x'*67),
726 > (b'n', b'', None, b'normal desc'),
731 > (b'n', b'', None, b'normal desc'),
727 > (b'', b'newline', b'', b'line1\nline2')],
732 > (b'', b'newline', b'', b'line1\nline2'),
733 > (b'', b'callableopt', func, b'adds foo'),
734 > (b'', b'customopt', customopt(''), b'adds bar'),
735 > (b'', b'customopt-withdefault', customopt('foo'), b'adds bar')],
728 > b'hg nohelp',
736 > b'hg nohelp',
729 > norepo=True)
737 > norepo=True)
730 > @command(b'debugoptADV', [(b'', b'aopt', None, b'option is (ADVANCED)')])
738 > @command(b'debugoptADV', [(b'', b'aopt', None, b'option is (ADVANCED)')])
@@ -786,10 +794,14 b' Test command with no help text'
786
794
787 options:
795 options:
788
796
789 --longdesc VALUE xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
797 --longdesc VALUE
790 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx (default: 3)
798 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
799 xxxxxxxxxxxxxxxxxxxxxxx (default: 3)
791 -n -- normal desc
800 -n -- normal desc
792 --newline VALUE line1 line2
801 --newline VALUE line1 line2
802 --callableopt VALUE adds foo
803 --customopt VALUE adds bar
804 --customopt-withdefault VALUE adds bar (default: foo)
793
805
794 (some details hidden, use --verbose to show complete help)
806 (some details hidden, use --verbose to show complete help)
795
807
General Comments 0
You need to be logged in to leave comments. Login now