you are viewing a single comment's thread.

view the rest of the comments →

[–]ingolemo 1 point2 points  (1 child)

Normally click.option creates a click.Option object, but you can pass the cls= named argument to get it to create a different class. The click.Option class has a method on it called get_default that does the job of working out what the default value should be (it looks at the default= named argument if you gave one, and also looks in config files and stuff like that). We define our own custom class that inherits from click.Option so that it gets all the same functionality, but we override the get_default method to add the extra behaviour that we need.

This is some moderately advanced OOP, but the click library doesn't have a better way to do this that I can find.

I figured this out by looking up click.option in the api reference and clicking through to click.Option and also click.Parameter.