def generate_completions(objects, incomplete, namespace):
    # We're completing something like `oc get pod/<tab>`.
    if "/" in incomplete:
        restypein = incomplete.split("/")[0]
        resname = incomplete.split("/")[1]
        names = get_resource_names(restypein, "_all", namespace)
        return [
            restypein + "/" + n
            for n in names
            if n.startswith(resname) and restypein + "/" + n not in objects
        ]

    if "," in incomplete or [o for o in objects if "," in o]:
        # This is a NOP like oc
        return []

    get_method, resource_list = parse.parse_get_resources(objects)

    # First arg after get, autocomplete type
    # or autocompleting after existing slash-notation arg
    if not objects or get_method == parse.Method.SLASH:
        if get_method == parse.Method.SLASH:
            add_slash = "/"
        else:
            add_slash = ""
        sugg = _suggest_type(incomplete)
        return [s + add_slash for s in sugg]

    if get_method == parse.Method.PLAIN and len(resource_list) > 0:
        # Autocomplete resource names based on the type: oc get pod mypod1 mypod2
        restypein, _ = next(resource_list)
        names = get_resource_names(restypein, "_all", namespace)
        return [n for n in names if n.startswith(incomplete) and n not in objects]
    # Catch all
    return []
Exemple #2
0
def complete_projects(ctx, args, incomplete):
    """
    Callback for project name autocompletion
    :return: List of matching namespace names or empty list.
    """
    if incomplete is not None:
        ns_listing = get_resource_names("project")
        suggestions = [ns for ns in ns_listing if ns.startswith(incomplete)]
        return suggestions
    return []
Exemple #3
0
def complete_mc(ctx, args, incomplete):
    """
    Callback for machine-config name autocompletion
    :return: List of matching machine-config names or empty list.
    """
    if incomplete is not None:
        mc_listing = get_resource_names("mc")
        suggestions = [ns for ns in mc_listing if ns.startswith(incomplete)]
        return suggestions
    return []