static void lbCommand_listBundles()

in bundles/shell/shell/src/lb_command.c [109:163]


static void lbCommand_listBundles(celix_bundle_context_t *ctx, const lb_options_t *opts, FILE *out) {
    celix_array_list_t* infoEntries = lbCommand_collectBundleInfo(ctx);

    const char* messageStr = "Name";
    if (opts->show_location) {
        messageStr = "Location";
    } else if (opts->show_symbolic_name) {
        messageStr = "Symbolic name";
    }

    const char* startColor = "";
    const char* endColor = "";
    if (opts->useColors) {
        startColor = HEAD_COLOR;
        endColor = END_COLOR;
    }
    fprintf(out, "%s  Bundles:%s\n", startColor, endColor);
    fprintf(out, "%s  %-5s %-12s %-40s %-20s%s\n", startColor, "ID", "State", messageStr, "Group", endColor);

    for (int i = 0; infoEntries != NULL && i < celix_arrayList_size(infoEntries); i++) {
        lb_command_bundle_info_t* info = celix_arrayList_get(infoEntries, i);

        const char* printValue = info->name;
        if (opts->show_location) {
            printValue = info->location;
        } else if (opts->show_symbolic_name) {
            printValue = info->symbolicName;
        }

        startColor = "";
        endColor = "";
        if (opts->useColors) {
            startColor = i % 2 == 0 ? EVEN_COLOR : ODD_COLOR;
            endColor = END_COLOR;
        }
        bool print = true;
        if (opts->listGroup != NULL) {
            print = info->group != NULL && strstr(info->group, opts->listGroup) != NULL;
        }

        if (print) {
            const char* printGroup = celix_utils_isStringNullOrEmpty(info->group) ? NONE_GROUP : info->group;
            fprintf(out, "%s  %-5li %-12s %-40s %-20s%s\n",
                    startColor,
                    info->id,
                    celix_bundleState_getName(info->state),
                    printValue,
                    printGroup,
                    endColor);
        }
    }
    fprintf(out, "\n\n");

    celix_arrayList_destroy(infoEntries);
}