@@ -63,7 +63,7 @@ def _get_usage(ctx: click.Context) -> str:
63
63
return formatter .getvalue ().rstrip ('\n ' ) # type: ignore
64
64
65
65
66
- def _get_help_record (opt : click .Option ) -> ty .Tuple [str , str ]:
66
+ def _get_help_record (ctx : click . Context , opt : click .Option ) -> ty .Tuple [str , str ]:
67
67
"""Re-implementation of click.Opt.get_help_record.
68
68
69
69
The variant of 'get_help_record' found in Click makes uses of slashes to
@@ -99,12 +99,17 @@ def _write_opts(opts: ty.List[str]) -> str:
99
99
100
100
extras = []
101
101
102
- if isinstance (opt .show_default , str ):
102
+ if opt .show_default is not None :
103
+ show_default = opt .show_default
104
+ else :
105
+ show_default = ctx .show_default
106
+
107
+ if isinstance (show_default , str ):
103
108
# Starting from Click 7.0 show_default can be a string. This is
104
109
# mostly useful when the default is not a constant and
105
110
# documentation thus needs a manually written string.
106
- extras .append (':default: ``%s``' % opt . show_default )
107
- elif opt .default is not None and opt . show_default :
111
+ extras .append (':default: ``%s``' % show_default )
112
+ elif opt .default is not None and show_default :
108
113
extras .append (
109
114
':default: ``%s``'
110
115
% (
@@ -165,9 +170,11 @@ def _format_usage(ctx: click.Context) -> ty.Generator[str, None, None]:
165
170
yield ''
166
171
167
172
168
- def _format_option (opt : click .Option ) -> ty .Generator [str , None , None ]:
173
+ def _format_option (
174
+ ctx : click .Context , opt : click .Option
175
+ ) -> ty .Generator [str , None , None ]:
169
176
"""Format the output for a `click.Option`."""
170
- opt_help = _get_help_record (opt )
177
+ opt_help = _get_help_record (ctx , opt )
171
178
172
179
yield '.. option:: {}' .format (opt_help [0 ])
173
180
if opt_help [1 ]:
@@ -196,7 +203,7 @@ def _format_options(ctx: click.Context) -> ty.Generator[str, None, None]:
196
203
]
197
204
198
205
for param in params :
199
- for line in _format_option (param ):
206
+ for line in _format_option (ctx , param ):
200
207
yield line
201
208
yield ''
202
209
0 commit comments