Is there interest in GOption support?



Aloha,

I've finally completed a patch that adds GOption support to Glib. It allows you to this (from the SYNOPSIS):

         my ($verbose, $source, $filenames) = ('', undef, []);

         my $entries = [
           { long_name => 'verbose',
             short_name => 'v',
             arg_type => 'none',
             arg_value => \$verbose,
             description => 'be verbose' },

           { long_name => 'source',
             short_name => 's',
             arg_type => 'string',
             arg_value => \$source,
             description => 'set the source',
             arg_description => 'source' },

           [ 'filenames', 'f', 'filename-array', \$filenames ],
         ];

         my $context = Glib::OptionContext->new ('- urgsify your life');
         $context->add_main_entries ($entries);
         $context->parse ();

         # $verbose, $source, and $filenames are now updated according to the
         # command line options given

If you call this program with --help, you will automatically get this:

         Usage:
           test.pl [OPTION...] - urgsify your life

         Help Options:
           -?, --help              Show help options

         Application Options:
           -v, --verbose           be verbose
           -s, --source=source     set the source
           -f, --filenames

You can also add gtk+'s options:

         $context->add_group (Gtk2->get_option_group (TRUE));

Now --help will also print this:

           --help-all               Show all help options
           --help-gtk               Show GTK+ Options

And --help-all and --help-gtk will do just what it says there.

The question now is: would you use this instead of any of the dozens of options parsers Perl already has? The patch adds quite a bit of code to Glib which we don't want to commit without there being demand for the feature.

(The performance impact of the patch seems to be negligible: any slowdown of 'use Glib' I could measure was within the error bounds.)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]