Skip to content

Instantly share code, notes, and snippets.

@stanchan
stanchan / mutually_exclusive_options.py
Created March 17, 2017 00:01
Python Click Mutually Exclusive Options
from click import command, option, Option, UsageError
class MutuallyExclusiveOption(Option):
def __init__(self, *args, **kwargs):
self.mutually_exclusive = set(kwargs.pop('mutually_exclusive', []))
help = kwargs.get('help', '')
if self.mutually_exclusive:
ex_str = ', '.join(self.mutually_exclusive)
kwargs['help'] = help + (
' NOTE: This argument is mutually exclusive with '