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 308886 - new goption flag G_OPTION_FLAG_OPTIONAL ARG
Product: glib
Classification: Platform
Component: general
Other All
: Normal enhancement
: ---
Assigned To: gtkdev
Depends on:
Blocks: 307312
Reported: 2005-06-24 04:03 UTC by Pawel Sliwowski
Modified: 2011-02-18 16:11 UTC
See Also:
GNOME target: ---
GNOME version: Unversioned Enhancement

add G_OPTION_FLAG_OPTION_ARG (8.88 KB, patch)
2005-06-24 04:04 UTC, Pawel Sliwowski
none Details | Review
Remove new flag (10.60 KB, patch)
2005-06-26 15:37 UTC, Pawel Sliwowski
none Details | Review

Description Pawel Sliwowski 2005-06-24 04:03:33 UTC
I was wondering if we could add a new goption flag G_OPTION_FLAG_OPTIONAL_ARG.
This flag would only apply to G_OPTION_ARG_CALLBACK like the other new flags,
but allows the argument to be optional. So this allows the switch to collect
data and act like a boolean. This is useful when you want a default action to be
taken if no argument is given.
Comment 1 Pawel Sliwowski 2005-06-24 04:04:50 UTC
Created attachment 48260 [details] [review]

2005-06-23  Pawel Sliwowski  <>

	* glib/goption.h:
	* glib/goption.c: Add G_OPTION_FLAG_OPTIONAL_ARG to 
	allow greater control of G_OPTION_ARG_CALLBACK options.

	* tests/option-test.c: test optional arg flag

2005-06-23  Pawel Sliwowski  <>

	* glib/tmpl/option.sgml (GOptionFlags): document
Comment 2 Matthias Clasen 2005-06-24 16:35:30 UTC
I'm not convinced we want to go further down the road of special flags.
The next thing somebody will propose is a flag to specify that a callback
takes 2 parameters, or 1 float and 2 ints...
Comment 3 Pawel Sliwowski 2005-06-24 17:05:30 UTC
The problem is ARG_CALLBACK is a last and only resort for special options.
Goption should not fail on a ARG_CALLBACK options, the callback function should
deal with it.

I personal would rather takeout all the new flags and let the callback function
deal with the details of how it should be dealt.

I can write patch to have ArgFunction to have gchar *value be gchar **value.

So we can have options that accepts 2 ints or whatever the developers wants as
long as he handles the cases within his callback function.

Again ARG_CALLBACK should allow the developer as much choice as possible, but
the trade will be complexity because of the generality.
Comment 4 Matthias Clasen 2005-06-24 17:36:54 UTC
That could be interesting, although I would have to see a concrete api proposal
Comment 5 Pawel Sliwowski 2005-06-26 15:37:14 UTC
Created attachment 48359 [details] [review]
Remove new flag

After trying to change the ArgFunction to gchar **, I realized there would be
to much complexity for the user and would behave very different from all the
rest of the options. So I just reverted back to my old patch, where I removed
all the new flags and just let G_OPTION_ARG_CALLBACK give NULL to ArgFunction
when no option is supplied. So it will be up to the user to return FALSE if an
argument was needed. Also took out the utf conversion. 

2005-06-26  Pawel Sliwowski  <open.list at>

	* glib/goption.h:
	* glib/goption.c: Removed new flags and and have  
	G_OPTION_ARG_CALLBACK send NULL to ArgFunction when
	no argument is supplied. Also no utf conversion is performed.

	* tests/option-test.c: test new callback function

2005-06-26  Pawel Sliwowski  <open.list at>

	* glib/tmpl/option.sgml (GOptionFlags): remove
	new flags documentation
Comment 6 Pawel Sliwowski 2005-06-26 15:44:14 UTC
If you don't like the new patch. Can you still add the optional_arg flag. I
think it is a very usually feature to have. I need to have arg optional for a
nautilus patch where the --browser switch will act like a filename_array, but
will have a default location if no argument is supplied with the switch.
Comment 7 Pawel Sliwowski 2005-07-04 16:08:40 UTC
Can I get some update on the status on this bug. I have another bug (307312)
that is being block by this one.
Comment 8 Matthias Clasen 2005-07-12 19:08:48 UTC
2005-07-12  Matthias Clasen  <>

	* glib/goption.h (G_OPTION_FLAG_NOALIAS): 
	* glib/goption.c: Add and implement a new flag
	to turn off the automatic <groupname>- prefixing
	for conflict resolution of long option names. (#171840,
	Adam McLaurin)
	All optional callback arguments  (#308886, Pawel

	* glib/goption.h (G_OPTION_FLAG_OPTIONAL_ARG): 
	* glib/goption.c: Add and implement a new flag
	to indicate that a callback *optionally* takes another

	* tests/option-test.c: Add tests for optional arguments.