Click: Option name alias / custom option name mapping

Created on 6 Feb 2017  路  3Comments  路  Source: pallets/click

Here's my code:

@click.command()
@click.option("--max")
def main(max):
    # ...

This works, but the problem is that the max parameter shadows the built-in function. I would like to change the function parameter name, but I don't want to change the option name. Is there a way to change the mapping? (I read through the docs rather thoroughly and haven't found the answer.)

docs good first issue

Most helpful comment

I would agree with @janpom about the documentation probably needing an example. I had this same problem today and first looked through the documentation and then the source code before finding this answer.

In my case I was trying to do @click.option("-a", "--all") which I think is a pretty common flag in CLIs and conflicts with the builtin all method.

All 3 comments

you can define the option with another name. the API documentation refers to these as param_decls; see Options for examples.

# ...
@click.option('--max', 'othermax')
def main(othermax):
    # ...

Thanks @brrzap. It's great this is possible.

I still think the documentation is slightly lacking in this respect. The param_decls doesn't have any reference, so it doesn't help much.

You're right that there's this example that does help, but it's not an obvious place to look at when looking for this information.

Anyway, thanks for the helpful response.

I would agree with @janpom about the documentation probably needing an example. I had this same problem today and first looked through the documentation and then the source code before finding this answer.

In my case I was trying to do @click.option("-a", "--all") which I think is a pretty common flag in CLIs and conflicts with the builtin all method.

Was this page helpful?
0 / 5 - 0 ratings