summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2020-10-14 11:51:29 +0200
committerBastien Nocera <hadess@hadess.net>2020-10-14 12:20:04 +0200
commit2cac8672262831dd0d246a74661d812f45637b35 (patch)
tree21a7afc2c0a2288b8e9e1b768650a6725d1a2939
parent41267156aa7923be0ecad40eeb884b040c6fe860 (diff)
downloadgnome-desktop-2cac8672262831dd0d246a74661d812f45637b35.tar.gz
thumbnail: Use GOption to parse command-line args in test
-rw-r--r--libgnome-desktop/test-desktop-thumbnail.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/libgnome-desktop/test-desktop-thumbnail.c b/libgnome-desktop/test-desktop-thumbnail.c
index 0ded2030..6a03425d 100644
--- a/libgnome-desktop/test-desktop-thumbnail.c
+++ b/libgnome-desktop/test-desktop-thumbnail.c
@@ -21,6 +21,8 @@
* Authors: Bastien Nocera <hadess@hadess.net>
*/
+#include <locale.h>
+
#define GNOME_DESKTOP_USE_UNSTABLE_API
#include <libgnome-desktop/gnome-desktop-thumbnail.h>
@@ -62,14 +64,35 @@ thumbnail_file (GnomeDesktopThumbnailFactory *factory,
int main (int argc, char **argv)
{
g_autoptr(GnomeDesktopThumbnailFactory) factory = NULL;
+ char **filenames = NULL;
+ int ret = 0;
+ g_autoptr(GOptionContext) option_context = NULL;
+ g_autoptr(GError) error = NULL;
+ const GOptionEntry options[] = {
+ { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, "[INPUT FILE] [OUTPUT FILE]", NULL },
+ { NULL}
+ };
+
+ setlocale (LC_ALL, "");
+ option_context = g_option_context_new ("");
+ g_option_context_add_main_entries (option_context, options, NULL);
+
+ ret = g_option_context_parse (option_context, &argc, &argv, &error);
+ if (!ret) {
+ g_print ("Failed to parse arguments: %s", error->message);
+ return EXIT_FAILURE;
+ }
- if (argc != 3) {
- g_print ("Usage: %s [INPUT FILE] [OUTPUT FILE]\n", argv[0]);
+ if (filenames == NULL ||
+ g_strv_length (filenames) != 2) {
+ g_autofree char *help = NULL;
+ help = g_option_context_get_help (option_context, TRUE, NULL);
+ g_print ("%s", help);
return 1;
}
factory = gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE);
- if (!thumbnail_file (factory, argv[1], argv[2]))
+ if (!thumbnail_file (factory, filenames[0], filenames[1]))
return 1;
return 0;