@staticmethod
    def metadata_arguments(bundle_subclasses):
        """
        Build arguments to a command-line argument parser for all metadata keys
        needed by the given bundle subclasses.
        """
        arguments = []
        added_keys = set()
        for bundle_subclass in bundle_subclasses:
            help_suffix = ' (for %ss)' % (bundle_subclass.BUNDLE_TYPE,) if bundle_subclass.BUNDLE_TYPE else ''

            for spec in bundle_subclass.get_user_defined_metadata():
                if spec.key not in added_keys:
                    added_keys.add(spec.key)

                    args = []
                    if spec.short_key:
                        args.append('-%s' % spec.short_key)
                    args.append('--%s' % spec.key.replace('_', '-'))

                    kwargs = {
                        'dest': metadata_util.metadata_key_to_argument(spec.key),
                        'help': spec.description + help_suffix,
                    }
                    if spec.completer is not None:
                        kwargs['completer'] = spec.completer
                    if issubclass(spec.type, list):
                        kwargs['type'] = str
                        kwargs['nargs'] = '*'
                        kwargs['metavar'] = spec.metavar
                    elif issubclass(spec.type, basestring):
                        kwargs['type'] = str
                        kwargs['metavar'] = spec.metavar
                    elif spec.type is bool:
                        kwargs['action'] = 'store_true'
                    else:
                        kwargs['type'] = spec.type
                        kwargs['metavar'] = spec.metavar
                    arguments.append(Commands.Argument(*args, **kwargs))

        return tuple(arguments)
dataset/ETHPy150Open codalab/codalab-cli/codalab/lib/bundle_cli.py/Commands.metadata_arguments/original