Skip to content

Commit

Permalink
Support numeric choices
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Finucane <stephen@that.guru>
Fixes: #75
  • Loading branch information
stephenfin committed Mar 18, 2021
1 parent 934c203 commit c4e6d71
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sphinx_click/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _write_opts(opts):
)

if isinstance(opt.type, click.Choice):
extras.append(':options: %s' % ' | '.join(opt.type.choices))
extras.append(':options: %s' % ' | '.join(str(x) for x in opt.type.choices))

if extras:
if out:
Expand Down
14 changes: 14 additions & 0 deletions tests/test_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
class CommandTestCase(unittest.TestCase):
"""Validate basic ``click.Command`` instances."""

maxDiff = None

def test_no_parameters(self):
"""Validate a `click.Command` with no parameters.
Expand Down Expand Up @@ -52,6 +54,12 @@ def test_basic_parameters(self):
help='A sample option with choices',
type=click.Choice(['Option1', 'Option2']),
)
@click.option(
'--numeric-choice',
metavar='<choice>',
help='A sample option with numeric choices',
type=click.Choice([1, 2, 3]),
)
@click.argument('ARG', envvar='ARG')
def foobar(bar):
"""A sample command."""
Expand Down Expand Up @@ -86,6 +94,12 @@ def foobar(bar):
:options: Option1 | Option2
.. option:: --numeric-choice <choice>
A sample option with numeric choices
:options: 1 | 2 | 3
.. rubric:: Arguments
.. option:: ARG
Expand Down

0 comments on commit c4e6d71

Please sign in to comment.