Skip to content

Commit 8d9037e

Browse files
#1768 added support for click.Choices in the help text
1 parent 376dead commit 8d9037e

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

SoftLayer/CLI/command.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@
1919

2020

2121
class OptionHighlighter(RegexHighlighter):
22-
"""Provides highlighter regex for the Command help"""
22+
"""Provides highlighter regex for the Command help.
23+
24+
Defined in SoftLayer\\utils.py console_color_themes()
25+
"""
2326
highlights = [
2427
r"(?P<switch>^\-\w)", # single options like -v
2528
r"(?P<option>\-\-[\w\-]+)", # long options like --verbose
2629
r"(?P<default_option>\[[^\]]+\])", # anything between [], usually default options
30+
r"(?P<option_choices>Choices: )",
2731
]
2832

2933

@@ -223,6 +227,11 @@ def format_options(self, ctx, formatter):
223227
if help_record:
224228
help_message = param.get_help_record(ctx)[-1]
225229

230+
# Add Click choices to help message
231+
if isinstance(param.type, click.Choice):
232+
choices = ", ".join(param.type.choices)
233+
help_message += f" Choices: {choices}"
234+
226235
if param.metavar:
227236
options += f" {param.metavar}"
228237
options_table.add_row(opt1, opt2, self.highlighter(help_message))

SoftLayer/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ def console_color_themes(theme):
481481
"default_option": "light_coral",
482482
"option_keyword": "bold dark_cyan",
483483
"args_keyword": "bold green4",
484+
"option_choices": "gold3",
484485
})
485486
)
486487
return Console(theme=Theme(
@@ -497,6 +498,7 @@ def console_color_themes(theme):
497498
"default_option": "light_pink1",
498499
"option_keyword": "bold cyan",
499500
"args_keyword": "bold green",
501+
"option_choices": "gold3",
500502
})
501503
)
502504

0 commit comments

Comments
 (0)