main: Honor --help and -h
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
...
This commit is contained in:
@ -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);
|
||||
|
||||
Reference in New Issue
Block a user