Let's say I want to name my verbose option v so it can be repeated (-vvv) but I want to refer to that variable in my code as verbosity. Currently I have to do that manually...
@click.command()
@click.option("-v", count=True)
def main(v):
verbosity = v
# etc.
...which seems odd when Click is otherwise so good at hiding the disconnect between what the user types and what the function itself looks like. I can assign a long name...
@click.command()
@click.option("-v", "--verbosity", count=True)
def main(verbosity):
# etc.
...but this leads to a wart where prog --verbosity --verbosity is possible, where I think I'd expect prog --verbosity=2. Allowing the user to set a name in the decorator seems the most elegant solution, especially since it would be orthogonal with the long argument...
@click.command()
@click.option("-v", "--verbose", name="verbosity", count=True)
def main(verbosity):
# etc.
...allowing for prog --verbose --verbose, which feels more grammatically correct to me.
You can already set a destination, which is useful if option names don't map to python identifiers, for example.
Copypastad from issue #227
@click.option('--7z', 'bin_7z')
...
def foo(bin_7z):
....
Ah, thanks. Not sure how I missed that.
For future readers landing here through Google: new version of link above is http://click.pocoo.org/parameters/#parameter-names
Most helpful comment
You can already set a destination, which is useful if option names don't map to python identifiers, for example.
Copypastad from issue #227
http://click.pocoo.org/3/parameters/#parameter-names