File tree 2 files changed +40
-5
lines changed
2 files changed +40
-5
lines changed Original file line number Diff line number Diff line change @@ -145,7 +145,7 @@ def _format_option(opt):
145
145
if opt [1 ]:
146
146
yield ''
147
147
for line in statemachine .string2lines (
148
- opt [1 ], tab_width = 4 , convert_whitespace = True
148
+ ANSI_ESC_SEQ_RE . sub ( '' , opt [1 ]) , tab_width = 4 , convert_whitespace = True
149
149
):
150
150
yield _indent (line )
151
151
@@ -241,12 +241,13 @@ def _format_epilog(ctx):
241
241
We parse this as reStructuredText, allowing users to embed rich
242
242
information in their help messages if they so choose.
243
243
"""
244
- epilog_string = ctx .command .epilog
245
- if not epilog_string :
244
+ if not ctx .command .epilog :
246
245
return
247
246
248
247
for line in statemachine .string2lines (
249
- epilog_string , tab_width = 4 , convert_whitespace = True
248
+ ANSI_ESC_SEQ_RE .sub ('' , ctx .command .epilog ),
249
+ tab_width = 4 ,
250
+ convert_whitespace = True ,
250
251
):
251
252
yield line
252
253
yield ''
Original file line number Diff line number Diff line change @@ -269,7 +269,23 @@ def hello(name):
269
269
def test_ansi_escape_sequences (self ):
270
270
"""Validate that ANSI escape sequences are stripped."""
271
271
272
- @click .command ()
272
+ @click .command (epilog = '\033 [31mA sample epilog.\033 [0m' )
273
+ @click .option (
274
+ '--name' ,
275
+ help = 'Name to say \033 [94mhello\033 [0m to.' ,
276
+ required = True ,
277
+ type = str ,
278
+ )
279
+ @click .option (
280
+ '--choice' ,
281
+ help = 'A sample option with choices' ,
282
+ type = click .Choice (['\033 [94mOption1\033 [0m' , '\033 [94mOption2\033 [0m' ]),
283
+ )
284
+ @click .option (
285
+ '--param' ,
286
+ default = lambda : None ,
287
+ show_default = 'Something computed at \033 [94mruntime\033 [0m' ,
288
+ )
273
289
def foobar ():
274
290
"""A sample command with **sparkles**.
275
291
@@ -293,6 +309,24 @@ def foobar():
293
309
.. code-block:: shell
294
310
295
311
foobar [OPTIONS]
312
+
313
+ .. rubric:: Options
314
+
315
+ .. option:: --name <name>
316
+
317
+ **Required** Name to say hello to.
318
+
319
+ .. option:: --choice <choice>
320
+
321
+ A sample option with choices
322
+
323
+ :options: Option1 | Option2
324
+
325
+ .. option:: --param <param>
326
+
327
+ :default: Something computed at runtime
328
+
329
+ A sample epilog.
296
330
"""
297
331
).lstrip (),
298
332
'\n ' .join (output ),
You can’t perform that action at this time.
0 commit comments