From 359376041d0a8f89895d45c89e3dac830453fbee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 21 Nov 2021 19:29:15 +0100 Subject: [PATCH] main: Honor --help and -h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use a GOptionContext to display command line options (that are already handled by e.g. gtk_init anyway). This turns: $ squeekboard -h Debug: Tried file "/home/agx/.local/share/squeekboard/keyboards/us.yaml", but it's missing: No such file or directory (os error 2) Info: Loaded layout Resource: us Debug: Tried file "/home/agx/.local/share/squeekboard/keyboards/us.yaml", but it's missing: No such file or directory (os error 2) Info: Loaded layout Resource: us ** (squeekboard:8015): WARNING **: 19:03:13.125: DBus unavailable, unclear how to continue. Is Squeekboard already running? into the more useful $ squeekboard -h Usage: squeekboard [OPTION…] - A on screen keyboard Help Options: -h, --help Show help options --help-all Show all help options --help-gtk Show GTK+ Options Application Options: --display=DISPLAY X display to use ... --- src/server-main.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/server-main.c b/src/server-main.c index 6e4e3673..fb0e0065 100644 --- a/src/server-main.c +++ b/src/server-main.c @@ -250,6 +250,21 @@ session_register(void) { int main (int argc, char **argv) { + g_autoptr (GError) err = NULL; + g_autoptr(GOptionContext) opt_context = NULL; + + const GOptionEntry options [] = { + { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL } + }; + opt_context = g_option_context_new ("- A on screen keyboard"); + + g_option_context_add_main_entries (opt_context, options, NULL); + g_option_context_add_group (opt_context, gtk_get_option_group (TRUE)); + if (!g_option_context_parse (opt_context, &argc, &argv, &err)) { + g_warning ("%s", err->message); + return 1; + } + if (!gtk_init_check (&argc, &argv)) { g_printerr ("Can't init GTK\n"); exit (1);