Re: Is there interest in GOption support?

--- On Sun, 11/16/08, Torsten Schoenfeld <kaffeetisch gmx de> wrote:

From: Torsten Schoenfeld <kaffeetisch gmx de>
Subject: Is there interest in GOption support?
To: gtk-perl-list gnome org
Date: Sunday, November 16, 2008, 3:50 AM

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:

  [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

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

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.)

My friend and I once (more than 10 year ago) developed very similar

So, I'm in favor of inclusion.



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