Last active
July 29, 2016 17:57
-
-
Save red-hood/f1b025682b51f21c2fc17c6ef1366c95 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from click.types import ParamType | |
from click.exceptions import BadParameter | |
class FallBackType(ParamType): | |
def __init__(self, fallback, def_type): | |
self.fallback = fallback | |
self.def_type = def_type | |
def convert(self, value, param, ctx): | |
try: | |
return self.def_type(value, param, ctx) | |
except BadParameter: | |
if callable(fallback): | |
return fallback(value, param, ctx) | |
return self.fallback |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment