<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def cmd(name, options=''):
 """ Decorator for all commands. Commands will receive (pymux, variables) as input. Commands can raise CommandException. """

    # Validate options.
    if options:
        try:
            docopt.docopt('Usage:\n    %s %s' % (name, options, ), [])
        except SystemExit:
            pass

    def decorator(func):
        def command_wrapper(pymux, arguments):
            # Hack to make the 'bind-key' option work.
            # (bind-key expects a variable number of arguments.)
            if name == 'bind-key' and '--' not in arguments:
                # Insert a double dash after the first non-option.
                for i, p in enumerate(arguments):
                    if not p.startswith('-'):
                        arguments.insert(i + 1, '--')
                        break

            # Parse options.
            try:
                # Python 2 workaround: pass bytes to docopt.
                # From the following, only the bytes version returns the right
                # output in Python 2:
                #   docopt.docopt('Usage:\n  app <params>...', [b'a', b'b'])
                #   docopt.docopt('Usage:\n  app <params>...', [u'a', u'b'])
                # https://github.com/docopt/docopt/issues/30
                # (Not sure how reliable this is...)
                if six.PY2:
                    arguments = [a.encode('utf-8') for a in arguments]

                received_options = docopt.docopt(
                    'Usage:\n    %s %s' % (name, options),
                    arguments,
                    help=False)  # Don't interpret the '-h' option as help.

                # Make sure that all the received options from docopt are
                # unicode objects. (Docopt returns 'str' for Python2.)
                for k, v in received_options.items():
                    if isinstance(v, six.binary_type):
                        received_options[k] = v.decode('utf-8')
            except SystemExit:
                raise CommandException('Usage: %s %s' % (name, options))

            # Call handler.
            func(pymux, received_options)

            # Invalidate all clients, not just the current CLI.
            pymux.invalidate()

        COMMANDS_TO_HANDLERS[name] = command_wrapper
        COMMANDS_TO_HELP[name] = options

        # Get list of option flags.
        flags = re.findall(r'-[a-zA-Z0-9]\b', options)
        COMMANDS_TO_OPTION_FLAGS[name] = flags

        return func
    return decorator