Re: popt in Gnome2::Program



On Mon, 2004-09-13 at 16:40, Peter Oliver wrote:
Usually I use Getopt::Long and Pod::Usage for command-line parsing.

I discovered that if want, say, session management to work, you need to 
call Gnome2::Program->init before Getopt::Long::GetOptions, so that Gnome 
can pick up and handle such options as --sm-client-id.  Arguments that 
Gnome doesn't know about are left in @ARGV for Getopt::Long to handle. 
So far so good.

The catch is that Gnome spots the --help option, displays help text 
about the default Gnome options, and exits.  You can't get the usage 
message straight from the pod with
     pod2usage( -verbose => 1 ) if $option{'help'};
anymore.

So, is there neat solution to this?  The best I've come up with is to put

     if ( grep { s/^-h$/--help/; m/^-(-help|\?)$/ } @ARGV ) {
         system $0, '--podhelp';
     }

at the top of my script.  Then, the secret '--podhelp' option triggers 
pod2usage.  It works, but the output is a bit of a mess, and it feels like 
cheating :-)

I've just come across this same issue and the resolution I came up with
was to simply allow --help to be taken care of by GNOME and instead use
-help for the application's usage. I've also documented that --help is
the Gtk2 usage info right along side the other help option indicators.


<code>
use Getopt::Long qw( :config no_ignore_case );
use Pod::Usage;

GetOptions( 'h|?'     => sub { pod2usage( 1 ); exit( 1 ); },
            'help'    => sub { pod2usage( -verbose => 2 ); exit( 1 ); },
            'usage'   => sub { pod2usage( 2 ); exit( 1 ); },
          ) or pod2usage(2);

...

init Gnome2::Program ( %app_opts );

...

__END__

=head1 NAME

odw - ODS GNU/Linux audio and data optical disc writing application

=head1 SYNOPSIS

 odw [options] [paths]

 Options:

  [ -h          ]      brief help message.
  [ -usage      ]      brief usage notes.
  [ -help       ]      help documentation.
  [ -?          ]      brief Gk2 message.
  [ --help      ]      Gtk2 documentation.
  [ --usage     ]      brief Gtk2 usage notes.

=head1 OPTIONS

...

</code>

Not sure if that helps you much but I thought I'd offer my two bits to
the plate.

-- 
Kevin C. Krinke <kckrinke opendoorsoftware com>
Open Door Software Inc.




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