GNOME Bugzilla – Bug 643650
GApplication documentation should mention GOption helpfully
Last modified: 2011-03-04 09:05:30 UTC
The GApplication documentation should explicitly suggest how to parse command-line arguments when using it. At the moment, you have to guess how to do it by following links that mention the "command-line" signal and then the "GApplicationCommandLine" object to find "g_application_command_line_get_arguments()" to get the argc/argv parameters that you can use with the GOption API: http://library.gnome.org/devel/glib/unstable/glib-Commandline-option-parser.html#glib-Commandline-option-parser.description Or you must guess that you can use the char*** argument of the local_command_line vfunc in the same way: http://library.gnome.org/devel/gio/unstable/GApplication.html#GApplicationClass.local-command-line I suggest something like this in the main description, with links where appropriate: " To parse command-line arguments you may handle the "command-line" signal or override the local_command_line() vfunc, to parse them in either the main instance or the local instance respectively. You may then obtain the argc and argv arguments for use with the GOption API. " And this could be added to the documentation for the "command-line" signal: " The GApplicationCommandLine object can provide the argc and argv parameters for use with the GOption command-line parsing API. " The documentation for the "local_command_line" vfunc would need something similar, but it would need an explicit clue about how to get the argc value, and that depends on documentation needed in bug #643478 . I also think that the GApplicationCommandLine overview and the documentation for g_application_command_line_get_arguments() http://library.gnome.org/devel/gio/unstable/GApplicationCommandLine.html#g-application-command-line-get-arguments should suggest that the results could be used with the GOption API. It currently has code for a "Complicated commandline handling" example, which does it without GOption, and that seems misleading: http://library.gnome.org/devel/gio/unstable/GApplicationCommandLine.html#gapplication-example-cmdline2
See also bug #624280.
I've taken some of these suggestions, and added an example. Note that there is currently no good way to do 'split handling' with GOption. Either --help only works for local options, or it only gives you docs for the remote options...
Thanks. Here is the example, as a note to myself: http://git.gnome.org/browse/glib/commit/?id=54e474931e4013cf0088df479018d9b7b156e637