def ParseFilesetRequirements(ref, args, request):
    """Fileset types need a file pattern."""
    del ref
    if args.type == 'fileset' and args.gcs_file_patterns is None:
        # if type is fileset and gcs-file-patterns not specified
        raise concept_exceptions.ModalGroupError('gcs-file-patterns',
                                                 'type=FILESET',
                                                 '--gcs-file-patterns')
    return request
Esempio n. 2
0
        def _ParseConcept(node):
            """Recursive parsing."""
            if not node.is_group:
                fallthroughs = []
                if node.arg_name:
                    fallthroughs.append(deps_lib.ArgFallthrough(node.arg_name))
                fallthroughs += node.fallthroughs
                return node.concept.Parse(
                    DependencyViewFromValue(
                        functools.partial(deps_lib.GetFromFallthroughs,
                                          fallthroughs, parsed_args),
                        marshalled_dependencies=node.dependencies))

            # TODO(b/120132521) Replace and eliminate argparse extensions
            also_optional = [
            ]  # The optional concepts that were not specified.
            have_optional = [
            ]  # The specified optional (not required) concepts.
            have_required = []  # The specified required concepts.
            need_required = []  # The required concepts that must be specified.
            namespace = {}
            for name, child in six.iteritems(node.dependencies):
                result = None
                try:
                    result = _ParseConcept(child)
                    if result:
                        if child.concept.required:
                            have_required.append(child.concept)
                        else:
                            have_optional.append(child.concept)
                    else:
                        also_optional.append(child.concept)
                except exceptions.MissingRequiredArgumentError:
                    need_required.append(child.concept)
                namespace[name] = result

            if need_required:
                missing = ' '.join(GetPresentationNames(need_required))
                if have_optional or have_required:
                    specified_parts = []
                    if have_required:
                        specified_parts.append(' '.join(
                            GetPresentationNames(have_required)))
                    if have_required and have_optional:
                        specified_parts.append(':')
                    if have_optional:
                        specified_parts.append(' '.join(
                            GetPresentationNames(have_optional)))

                    specified = ' '.join(specified_parts)
                    if have_required and have_optional:
                        if node.concept.required:
                            specified = '({})'.format(specified)
                        else:
                            specified = '[{}]'.format(specified)
                    raise exceptions.ModalGroupError(
                        node.concept.GetPresentationName(), specified, missing)

            count = len(have_required) + len(have_optional)
            if node.concept.mutex:
                specified = ' | '.join(
                    GetPresentationNames(node.concept.concepts))
                if node.concept.required:
                    specified = '({specified})'.format(specified=specified)
                    if count != 1:
                        raise exceptions.RequiredMutexGroupError(
                            node.concept.GetPresentationName(), specified)
                else:
                    if count > 1:
                        raise exceptions.OptionalMutexGroupError(
                            node.concept.GetPresentationName(), specified)

            return node.concept.Parse(DependencyView(namespace))