From d76643ee47551ba234e1ac3a731106d49724855b Mon Sep 17 00:00:00 2001 From: Leandro Ribeiro Date: Fri, 19 Apr 2024 17:18:18 -0300 Subject: [PATCH] clients/image: print program usage Add function to print program usage. For now this is kind of useless, but in the next commit we'll add more functionalities to clients/image command line options. Signed-off-by: Leandro Ribeiro --- clients/image.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/clients/image.c b/clients/image.c index 1feb2182..230f042d 100644 --- a/clients/image.c +++ b/clients/image.c @@ -43,6 +43,7 @@ #include "window.h" #include "shared/cairo-util.h" +#include "shared/helpers.h" #include "shared/image-loader.h" struct image { @@ -493,6 +494,15 @@ image_create(struct display *display, const char *filename, return image; } +static void +print_usage(const char *program_name) +{ + fprintf(stderr, "Usage:\n %s [OPTIONS] [FILENAME0] [FILENAME1] ...\n\n" \ + "Options:\n", program_name); + + fprintf(stderr, "-h or --help to open this HELP dialogue.\n"); +} + int main(int argc, char *argv[]) { @@ -500,9 +510,15 @@ main(int argc, char *argv[]) int i; int image_counter = 0; int render_intent; + bool opt_help = false; + struct weston_option cli_options[] = { + { WESTON_OPTION_BOOLEAN, "help", 'h', &opt_help }, + }; - if (argc <= 1 || argv[1][0]=='-') { - printf("Usage: %s image...\n", argv[0]); + parse_options(cli_options, ARRAY_LENGTH(cli_options), &argc, argv); + + if (argc <= 1 || opt_help) { + print_usage(argv[0]); return 1; }