(value, default=None)
| 710 | |
| 711 | |
| 712 | def as_boolean(value, default=None): # type: (Any, Optional[bool]) -> bool |
| 713 | if isinstance(value, bool): |
| 714 | return value |
| 715 | |
| 716 | if isinstance(value, int): |
| 717 | return value > 0 |
| 718 | |
| 719 | if isinstance(value, str) and len(value) > 0: |
| 720 | value = value.lower() |
| 721 | if value in ('yes', 'y', 'on', '1', 'true', 't'): |
| 722 | return True |
| 723 | if value in ('no', 'n', 'off', '0', 'false', 'f'): |
| 724 | return False |
| 725 | |
| 726 | if default is not None and isinstance(default, bool): |
| 727 | return default |
| 728 | |
| 729 | raise Exception("Unknown value. Available values 'yes'/'no', 'y'/'n', 'on'/'off', '1'/'0', 'true'/'false'") |
| 730 | |
| 731 | |
| 732 | class CliCommand(abc.ABC): |
no outgoing calls
no test coverage detected