Skip to content

Option name alias / custom option name mapping #725

Closed

Description

@janpom

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.)

Activity

  1. brrzap commented on May 2, 2017

    @brrzap

    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):
        # ...
    
  2. janpom commented on May 2, 2017

    @janpom
    Author

    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.

  3. scottbelden commented on May 17, 2017

    @scottbelden
    Contributor

    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.

  4. added
    docs
    on May 16, 2018
  5. added this to the 7.0 milestone on Sep 10, 2018
  6. added 2 commits that reference this issue on Oct 8, 2018
  7. added a commit that references this issue on Oct 29, 2018
  8. locked as resolved and limited conversation to collaborators on Nov 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docs

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions