GNOME Bugzilla – Bug 308886
new goption flag G_OPTION_FLAG_OPTIONAL ARG
Last modified: 2011-02-18 16:11:07 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.
Created attachment 48260 [details] [review] add G_OPTION_FLAG_OPTION_ARG 2005-06-23 Pawel Sliwowski <open.list@gmail.com> * 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 <open.list@gmail.com> * glib/tmpl/option.sgml (GOptionFlags): document G_OPTION_FLAG_OPTIONAL_ARG
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...
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.
That could be interesting, although I would have to see a concrete api proposal
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 gmail.com> * 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 gmail.com> * glib/tmpl/option.sgml (GOptionFlags): remove new flags documentation
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.
Can I get some update on the status on this bug. I have another bug (307312) that is being block by this one.
2005-07-12 Matthias Clasen <mclasen@redhat.com> * 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 Sliwowski) * 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 argument. * tests/option-test.c: Add tests for optional arguments.