Skip to content

Commit

Permalink
Support 'metavar'
Browse files Browse the repository at this point in the history
We need to be careful here to strip out potential option markers.

Signed-off-by: Stephen Finucane <[email protected]>
Closes: #6
  • Loading branch information
stephenfin committed Jul 23, 2020
1 parent b511f56 commit 382d7e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion sphinx_click/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ def _get_help_record(opt):
def _write_opts(opts):
rv, _ = click.formatting.join_options(opts)
if not opt.is_flag and not opt.count:
rv += ' <{}>'.format(opt.name)
name = opt.name
if opt.metavar:
name = opt.metavar.lstrip('<[{($').rstrip('>]})$')
rv += ' <{}>'.format(name)
return rv

rv = [_write_opts(opt.opts)]
Expand Down
5 changes: 5 additions & 0 deletions tests/test_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def test_basic_parameters(self):

@click.command()
@click.option('--param', envvar='PARAM', help='A sample option')
@click.option('--another', metavar='[FOO]', help='Another option')
@click.option(
'--choice',
help='A sample option with choices',
Expand Down Expand Up @@ -75,6 +76,10 @@ def foobar(bar):
A sample option
.. option:: --another <FOO>
Another option
.. option:: --choice <choice>
A sample option with choices
Expand Down

0 comments on commit 382d7e5

Please sign in to comment.