Skip to content

Commit 382d7e5

Browse files
committed
Support 'metavar'
We need to be careful here to strip out potential option markers. Signed-off-by: Stephen Finucane <stephen@that.guru> Closes: #6
1 parent b511f56 commit 382d7e5

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

sphinx_click/ext.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ def _get_help_record(opt):
4444
def _write_opts(opts):
4545
rv, _ = click.formatting.join_options(opts)
4646
if not opt.is_flag and not opt.count:
47-
rv += ' <{}>'.format(opt.name)
47+
name = opt.name
48+
if opt.metavar:
49+
name = opt.metavar.lstrip('<[{($').rstrip('>]})$')
50+
rv += ' <{}>'.format(name)
4851
return rv
4952

5053
rv = [_write_opts(opt.opts)]

tests/test_formatter.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def test_basic_parameters(self):
4646

4747
@click.command()
4848
@click.option('--param', envvar='PARAM', help='A sample option')
49+
@click.option('--another', metavar='[FOO]', help='Another option')
4950
@click.option(
5051
'--choice',
5152
help='A sample option with choices',
@@ -75,6 +76,10 @@ def foobar(bar):
7576
7677
A sample option
7778
79+
.. option:: --another <FOO>
80+
81+
Another option
82+
7883
.. option:: --choice <choice>
7984
8085
A sample option with choices

0 commit comments

Comments
 (0)