After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 643650 - GApplication documentation should mention GOption helpfully
GApplication documentation should mention GOption helpfully
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gapplication
2.28.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks: 637445
 
 
Reported: 2011-03-02 08:20 UTC by Murray Cumming
Modified: 2011-03-04 09:05 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Murray Cumming 2011-03-02 08:20:40 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
Comment 1 Murray Cumming 2011-03-03 14:28:37 UTC
See also bug #624280.
Comment 2 Matthias Clasen 2011-03-04 06:33:47 UTC
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...
Comment 3 Murray Cumming 2011-03-04 09:05:30 UTC
Thanks.
Here is the example, as a note to myself:
http://git.gnome.org/browse/glib/commit/?id=54e474931e4013cf0088df479018d9b7b156e637