From e9cc9eefa6a3ee1b20269f323fc577f3e9473d76 Mon Sep 17 00:00:00 2001 From: Charles Giessen Date: Tue, 16 Nov 2021 19:51:45 -0700 Subject: vulkaninfo: Error check --output Make sure the following argument is a filename and not another argument. Also: Add `--text` as it makes sense to have it as an explicit flag even if it is the default. Move --summary to the top, since its the most useful thing to know at a glance. --- vulkaninfo/vulkaninfo.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'vulkaninfo/vulkaninfo.cpp') diff --git a/vulkaninfo/vulkaninfo.cpp b/vulkaninfo/vulkaninfo.cpp index 8be482e9..75443a35 100644 --- a/vulkaninfo/vulkaninfo.cpp +++ b/vulkaninfo/vulkaninfo.cpp @@ -818,6 +818,9 @@ void print_usage(const char *argv0) { std::cout << "USAGE: " << argv0 << " [options]\n\n"; std::cout << "OPTIONS:\n"; std::cout << "-h, --help Print this help.\n"; + std::cout << "--summary Show a summary of the instance and GPU's on a system.\n\n"; + std::cout << "--text Produce a text version of vulkaninfo output to stdout. This is\n"; + std::cout << " the default output.\n"; std::cout << "--html Produce an html version of vulkaninfo output, saved as\n"; std::cout << " \"vulkaninfo.html\" in the directory in which the command\n"; std::cout << " is run.\n"; @@ -841,7 +844,6 @@ void print_usage(const char *argv0) { std::cout << "-o , --output\n"; std::cout << " Print output to a new file whose name is specified by filename.\n"; std::cout << " File will be written to the current working directory.\n"; - std::cout << "--summary Show a summary of the instance and GPU's on a system.\n\n"; } struct ParsedResults { @@ -862,8 +864,10 @@ util::trivial_optional parse_arguments(int argc, char **argv) { // Usage "--vkconfig_output " if (0 == strcmp("--vkconfig_output", argv[i]) && argc > (i + 1)) { results.output_category = OutputCategory::vkconfig_output; - results.output_path = argv[i + 1]; - ++i; + if (argc > (i + 1) && argv[i + 1][0] != '-') { + results.output_path = argv[i + 1]; + ++i; + } } else if (strncmp("--json", argv[i], 6) == 0 || strcmp(argv[i], "-j") == 0) { if (strlen(argv[i]) > 7 && strncmp("--json=", argv[i], 7) == 0) { results.selected_gpu = static_cast(strtol(argv[i] + 7, nullptr, 10)); @@ -879,6 +883,8 @@ util::trivial_optional parse_arguments(int argc, char **argv) { #endif // defined(VK_ENABLE_BETA_EXTENSIONS) } else if (strcmp(argv[i], "--summary") == 0) { results.output_category = OutputCategory::summary; + } else if (strcmp(argv[i], "--text") == 0) { + results.output_category = OutputCategory::text; } else if (strcmp(argv[i], "--html") == 0) { } else if (strcmp(argv[i], "--show-tool-props") == 0) { results.show_tool_props = true; @@ -887,6 +893,10 @@ util::trivial_optional parse_arguments(int argc, char **argv) { } else if ((strcmp(argv[i], "--output") == 0 || strcmp(argv[i], "-o") == 0) && argc > (i + 1)) { results.use_custom_filename = true; results.custom_filename = argv[i + 1]; + if (argv[i + 1][0] == '-') { + std::cout << "-o or --output must be followed by a filename\n"; + return {}; + } ++i; } else if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) { print_usage(argv[0]); -- cgit v1.2.3