def parse_feature_kvp_nargs()

in azext_edge/edge/providers/orchestration/resources/instances.py [0:0]


def parse_feature_kvp_nargs(features: Optional[List[str]] = None, strict: bool = False) -> Optional[Dict[str, dict]]:
    features: Dict[str, str] = parse_kvp_nargs(features)
    if not features:
        return features

    if strict:
        ensure_feature_key_compat(features)

    features_payload = {}
    errors = []
    mode_pattern = re.compile(r"^\w+\.mode$")
    setting_pattern = re.compile(r"^\w+\.settings\.[^.\s]+$")

    for key in features:
        if not (mode_pattern.match(key) or setting_pattern.match(key)):
            errors.append(
                f"{key} is invalid. Feature keys must be in the form "
                f"'{{component}}.mode' or '{{component}}.settings.{{setting}}'."
            )
            continue

        split_key = key.split(".")
        split_key_len = len(split_key)
        nested_key = "settings" if split_key_len >= 3 else "mode"
        if split_key[0] not in features_payload:
            features_payload[split_key[0]] = {}
        if nested_key == "settings":
            if "settings" not in features_payload[split_key[0]]:
                features_payload[split_key[0]][nested_key] = {}
            if features[key] not in ["Enabled", "Disabled"]:
                errors.append(f"{key} has an invalid value. Known setting values are: 'Enabled' or 'Disabled'.")
                continue
            features_payload[split_key[0]][nested_key][split_key[2]] = features[key]
        if nested_key == "mode":
            if features[key] not in ["Stable", "Preview", "Disabled"]:
                errors.append(f"{key} has an invalid value. Known mode values are: 'Stable', 'Preview' or 'Disabled'.")
                continue
            features_payload[split_key[0]][nested_key] = features[key]

    if errors:
        raise InvalidArgumentValueError("\n".join(errors))

    return features_payload