diff --git a/src/common/args.cpp b/src/common/args.cpp index cdab8f2..6e1aa85 100644 --- a/src/common/args.cpp +++ b/src/common/args.cpp @@ -246,11 +246,22 @@ bool parse_args(int argc, char* argv[]) { } } else if(opt == args_chr[ARG_GPU]) { - args.gpu_idx = getarg_int(optarg); - if(errn != 0) { - printErr("Option %s: %s", args_str[ARG_GPU], getarg_error()); - args.help_flag = true; - return false; + // Check for "a" option + if(strcmp(optarg, "a") == 0) { + args.gpu_idx = -1; + } + else { + args.gpu_idx = getarg_int(optarg); + if(errn != 0) { + printErr("Option %s: %s", args_str[ARG_GPU], getarg_error()); + args.help_flag = true; + return false; + } + if(args.gpu_idx < 0) { + printErr("Specified GPU index is out of range: %d. ", args.gpu_idx); + printf("Run gpufetch with the --%s option to check out valid GPU indexes\n", args_str[ARG_LIST]); + return false; + } } } else if(opt == args_chr[ARG_LIST]) { diff --git a/src/common/main.cpp b/src/common/main.cpp index f7c2506..84ad9d5 100644 --- a/src/common/main.cpp +++ b/src/common/main.cpp @@ -21,7 +21,7 @@ void print_help(char *argv[]) { printf("Options: \n"); printf(" -%c, --%s %*s Set the color scheme (by default, gpufetch uses the system color scheme) See COLORS section for a more detailed explanation\n", c[ARG_COLOR], t[ARG_COLOR], (int) (max_len-strlen(t[ARG_COLOR])), ""); printf(" -%c, --%s %*s List the available GPUs in the system\n", c[ARG_LIST], t[ARG_LIST], (int) (max_len-strlen(t[ARG_LIST])), ""); - printf(" -%c, --%s %*s Select the GPU to use (default: 0)\n", c[ARG_GPU], t[ARG_GPU], (int) (max_len-strlen(t[ARG_GPU])), ""); + printf(" -%c, --%s %*s Select the GPU to print (default: 0). Use 'a' to print all GPUs\n", c[ARG_GPU], t[ARG_GPU], (int) (max_len-strlen(t[ARG_GPU])), ""); printf(" --%s %*s Show the short version of the logo\n", t[ARG_LOGO_SHORT], (int) (max_len-strlen(t[ARG_LOGO_SHORT])), ""); printf(" --%s %*s Show the long version of the logo\n", t[ARG_LOGO_LONG], (int) (max_len-strlen(t[ARG_LOGO_LONG])), ""); printf(" -%c, --%s %*s Enable verbose output\n", c[ARG_VERBOSE], t[ARG_VERBOSE], (int) (max_len-strlen(t[ARG_VERBOSE])), ""); @@ -72,9 +72,6 @@ int main(int argc, char* argv[]) { set_log_level(verbose_enabled()); int idx = get_gpu_idx(); - if(!gpu_idx_valid(idx)) { - return EXIT_FAILURE; - } struct gpu_list* list = get_gpu_list(); if(list_gpus()) { @@ -91,17 +88,33 @@ int main(int argc, char* argv[]) { return EXIT_FAILURE; } - struct gpu_info* gpu = get_gpu_info(list, idx); - if(gpu == NULL) - return EXIT_FAILURE; + int first_idx, last_idx; + if(idx == -1) { + first_idx = 0; + last_idx = get_num_gpus_available(list); + } + else { + first_idx = idx; + last_idx = idx+1; + } - printf("[NOTE]: gpufetch is in beta. The provided information may be incomplete or wrong.\n\ + bool print_failed = false; + struct gpu_info* gpu = NULL; + for(int gpu_idx = first_idx; !print_failed && gpu_idx < last_idx; gpu_idx++) { + gpu = get_gpu_info(list, gpu_idx); + if(gpu == NULL) + return EXIT_FAILURE; + + printf("[NOTE]: gpufetch is in beta. The provided information may be incomplete or wrong.\n\ If you want to help to improve gpufetch, please compare the output of the program\n\ with a reliable source which you know is right (e.g, techpowerup.com) and report\n\ any inconsistencies to https://github.com/Dr-Noob/gpufetch/issues\n"); - if(print_gpufetch(gpu, get_style(), get_colors())) - return EXIT_SUCCESS; - else - return EXIT_FAILURE; + if(!print_gpufetch(gpu, get_style(), get_colors())) { + print_failed = true; + } + } + + if(print_failed) return EXIT_SUCCESS; + else return EXIT_FAILURE; } diff --git a/src/common/master.cpp b/src/common/master.cpp index 2a65a2d..a5694f3 100644 --- a/src/common/master.cpp +++ b/src/common/master.cpp @@ -81,15 +81,6 @@ int get_num_gpus_available(struct gpu_list* list) { return list->num_gpus; } -bool gpu_idx_valid(int idx) { - if(idx < 0) { - printErr("Specified GPU index is out of range: %d. ", idx); - printf("Run gpufetch with the --%s option to check out valid GPU indexes\n", args_str[ARG_LIST]); - return false; - } - return true; -} - struct gpu_info* get_gpu_info(struct gpu_list* list, int idx) { if(idx >= list->num_gpus || idx < 0) { printErr("Specified GPU index is out of range: %d", idx); diff --git a/src/common/master.hpp b/src/common/master.hpp index 8de7b3a..ad710c5 100644 --- a/src/common/master.hpp +++ b/src/common/master.hpp @@ -9,7 +9,6 @@ struct gpu_list* get_gpu_list(); bool print_gpus_list(struct gpu_list* list); int get_num_gpus_available(struct gpu_list* list); void print_enabled_backends(); -bool gpu_idx_valid(int idx); struct gpu_info* get_gpu_info(struct gpu_list* list, int idx); #endif