# Buggy code
def register_cache_arguments(cli_ctx):
    from knack import events
    from azure.cli.core.commands.parameters import CaseInsensitiveList

    cache_dest = "_cache"

    def add_cache_arguments(_, **kwargs):  # pylint: disable=unused-argument
        command_table = kwargs.get("commands_loader").command_table

        if not command_table:
            return

        class CacheAction(argparse.Action):  # pylint:disable=too-few-public-methods
            def __call__(self, parser, namespace, values, option_string=None):
                setattr(namespace, cache_dest, values)
                # save caching status to CLI context
                cmd = getattr(namespace, "cmd", None) or getattr(
                    namespace, "_cmd", None
                )
                cmd.cli_ctx.data[cache_dest] = values

        for command in command_table.values():
            supports_local_cache = command.command_kwargs.get("supports_local_cache")
            if supports_local_cache:
                command.arguments[cache_dest] = CLICommandArgument(
                    "_cache",
                    options_list="--cache",
                    arg_group="Caching Strategy",
                    nargs="+",
                    choices=CaseInsensitiveList(["read", "write", "write-through"]),
                    action=CacheAction,
                    help="Space-separated list of caching directives.",
                )

    cli_ctx.register_event(
        events.EVENT_INVOKER_POST_CMD_TBL_CREATE, add_cache_arguments
    )


# Traceback (TypeError)
join() argument must be str or bytes, not 'NoneType'
Traceback (most recent call last):
python3.7/site-packages/knack/cli.py, ln 206, in invoke
cmd_result = self.invocation.execute(args)
cli/core/commands/__init__.py, ln 523, in execute
raise ex
cli/core/commands/__init__.py, ln 581, in _run_jobs_serially
results.append(self._run_job(expanded_arg, cmd_copy))
cli/core/commands/__init__.py, ln 574, in _run_job
six.reraise(*sys.exc_info())
...
cli/command_modules/configure/custom.py, ln 194, in show_cache_contents
item_path = os.path.join(directory, resource_group_name, resource_type, '{}.json'.format(item_name))
../lib/python3.7/posixpath.py, ln 94, in join
genericpath._check_arg_types('join', a, *p)
../lib/python3.7/genericpath.py, ln 149, in _check_arg_types
(funcname, s.__class__.__name__)) from None
TypeError: join() argument must be str or bytes, not 'NoneType'

# Fixed code
def register_cache_arguments(cli_ctx):
    from knack import events

    cache_dest = "_cache"

    def add_cache_arguments(_, **kwargs):  # pylint: disable=unused-argument
        command_table = kwargs.get("commands_loader").command_table

        if not command_table:
            return

        class CacheAction(argparse.Action):  # pylint:disable=too-few-public-methods
            def __call__(self, parser, namespace, values, option_string=None):
                setattr(namespace, cache_dest, True)
                # save caching status to CLI context
                cmd = getattr(namespace, "cmd", None) or getattr(
                    namespace, "_cmd", None
                )
                cmd.cli_ctx.data[cache_dest] = True

        for command in command_table.values():
            supports_local_cache = command.command_kwargs.get("supports_local_cache")
            if supports_local_cache:
                command.arguments[cache_dest] = CLICommandArgument(
                    "_cache",
                    options_list="--defer",
                    nargs="?",
                    action=CacheAction,
                    help="Temporarily store the object in the local cache instead of sending to Azure. "
                    "Use `az cache` commands to view/clear.",
                )

    cli_ctx.register_event(
        events.EVENT_INVOKER_POST_CMD_TBL_CREATE, add_cache_arguments
    )