Exemplo n.º 1
0
int main(int argc, char *argv[]) {
	int ret = EOK;
    struct scl_args *args;
    char **pkgs = NULL;
    char **colls = NULL, **colls2 = NULL, **colls_merged = NULL;

    ret = scl_args_get(argc, argv, &args);
    if (ret == EINPUT) {
        fprintf(stderr, "Wrong arguments specified!\n\n");
        print_usage(argv[0]);

        return ret;
    } else if (ret != EOK) {
        fprintf(stderr, "Unspecified error when parsing arguments!\n\n");

        return ret;
    }


    switch (args->action) {
        case ACTION_NONE:
            print_usage(argv[0]);
            break;

        case ACTION_LIST_COLLECTIONS:
            ret = fallback_get_installed_collections(&colls);
            if (ret == EOK) {
                print_string_array(colls);
            }
            break;

        case ACTION_LIST_PACKAGES:
            ret = list_packages_in_collection(args->collections[0], &pkgs);
            if (ret == EOK) {
                print_string_array(pkgs);
            }
            break;

        case ACTION_COMMAND:
            if (has_old_collection(args->collections)) {
                ret = fallback_run_command(args->collections, args->command, args->exec_flag);
            } else {
                ret = run_command(args->collections, args->command, args->exec_flag);
            }
            break;
        case ACTION_REGISTER:
            ret = register_collection(args->colpaths[0]);
            break;
        case ACTION_DEREGISTER:
            ret = deregister_collection(args->collections[0], args->force_flag);
            break;
        case ACTION_MAN:
            ret = show_man(args->collections[0]);
            break;
        case ACTION_LOAD:
        case ACTION_UNLOAD:
            debug("Missing function scl in your environment!!!\n");
            ret = ECONFIG;
            break;
        case ACTION_VERSION:
            printf("%s\n", get_version());
            break;
        case ACTION_LIST_ENABLED:
            /* Get enabled collections of new type */
            ret = get_enabled_collections(&colls);
            if (ret != EOK) {
                break;
            }
            /* Get enabled collections of old type */
            ret = fallback_get_enabled_collections(&colls2);
            if (ret != EOK) {
                break;
            }

            /*
             * Some new collections can behave like old collections by defining
             * variable X_SCLS. There may be intersection between colls and
             * colls2. So merge them.
             */
            colls_merged = merge_string_arrays(colls, colls2);
            print_string_array(colls_merged);

            break;
    }

    scl_args_free(args);
    free(args);
    free_string_array(pkgs);
    free_string_array(colls);
    free_string_array(colls2);
    free_string_array(colls_merged);
    release_scllib_cache();
    return ret;
}
Exemplo n.º 2
0
int main(int argc, char *argv[]) {
	int ret = EOK;
    struct scl_args *args;
    char **pkgs = NULL;
    char **colls = NULL;

    ret = scl_args_get(argc, argv, &args);
    if (ret == EINPUT) {
        fprintf(stderr, "Wrong arguments specified!\n\n");
        print_usage(argv[0]);

        return ret;
    } else if (ret != EOK) {
        fprintf(stderr, "Unspecified error when parsing arguments!\n\n");

        return ret;
    }


    switch (args->action) {
        case ACTION_NONE:
            print_usage(argv[0]);
            break;

        case ACTION_LIST_COLLECTIONS:
            ret = fallback_get_installed_collections(&colls);
            if (ret == EOK) {
                print_string_array(colls);
                free_string_array(colls);
            }
            break;

        case ACTION_LIST_PACKAGES:
            ret = list_packages_in_collection(args->collections[0], &pkgs);
            if (ret == EOK) {
                print_string_array(pkgs);
                free_string_array(pkgs);
            }
            break;

        case ACTION_COMMAND:
            if (has_old_collection(args->collections)) {
                ret = fallback_run_command(args->collections, args->command, args->exec_flag);
            } else {
                ret = run_command(args->collections, args->command, args->exec_flag);
            }
            break;
        case ACTION_REGISTER:
            ret = register_collection(args->colpaths[0]);
            break;
        case ACTION_DEREGISTER:
            ret = deregister_collection(args->collections[0], args->force_flag);
            break;
        case ACTION_MAN:
            ret = show_man(args->collections[0]);
            break;
        case ACTION_LOAD:
        case ACTION_UNLOAD:
            debug("Missing function scl in your environment!!!\n");
            ret = ECONFIG;
            break;
        case ACTION_VERSION:
            printf("%s\n", get_version());
            break;
    }

    scl_args_free(args);
    free(args);
    release_scllib_cache();
    return ret;
}