Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions sphinxarg/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ def render_list(l, markdown_help, settings=None):
return all_children


def format_choices(choices):
if isinstance(choices, range) and choices.step == 1:
return f'Value range: {choices.start} to {choices.stop}\n'
return f'Possible choices: {", ".join(str(c) for c in choices)}\n'


def _is_suppressed(item: str | None) -> bool:
"""Return whether item should not be printed."""
if item is None:
Expand Down Expand Up @@ -157,9 +163,7 @@ def print_action_groups(
# Build the help text
arg = []
if 'choices' in entry:
arg.append(
f"Possible choices: {', '.join(str(c) for c in entry['choices'])}\n"
)
arg.append(format_choices(entry['choices']))
if 'help' in entry:
arg.append(entry['help'])
if not _is_suppressed(entry['default']):
Expand Down Expand Up @@ -400,9 +404,7 @@ def _format_positional_arguments(self, parser_info):
elif 'choices' not in arg:
arg_items.append(nodes.paragraph(text='Undocumented'))
if 'choices' in arg:
arg_items.append(
nodes.paragraph(text='Possible choices: ' + ', '.join(arg['choices']))
)
arg_items.append(nodes.paragraph(text=format_choices(arg['choices'])))
items.append(
nodes.option_list_item(
'',
Expand Down Expand Up @@ -432,9 +434,7 @@ def _format_optional_arguments(self, parser_info):
elif 'choices' not in opt:
opt_items.append(nodes.paragraph(text='Undocumented'))
if 'choices' in opt:
opt_items.append(
nodes.paragraph(text='Possible choices: ' + ', '.join(opt['choices']))
)
opt_items.append(nodes.paragraph(text=format_choices(opt['choices'])))
items.append(
nodes.option_list_item(
'',
Expand Down