On Dec 13, 2003, at 10:01 AM, Wiggins d'Anconia wrote: [..
A decent template, any gurus have improvements?[..]
my stock gag, looks like:
my $opt = parse_cmd_line_options(); ... #--------------------------------------------------------------- # These are the Subs for the parse_cmd_line_options. #--------------------------------------------------------------- # The Usage Command so that we can use a common interface to # handle both the cases where we want to show some basic detailed # information with a '--help' query, as well as to exit out of # the parse_cmd_line_options wrapper for Getopt::Long if we have # problems with user generated commands. #---------------------------------------------------------------
sub Usage
{
my($msg, $retval, @list) = @_;print "$msg\n" if ($msg);
print "Usage: $0 [-i|-x|-c|--kadb] [-f <alt_file>] [-d <sysname>]\n";
if ( @list ) {
print " the full optins list is:\n";
print "\t$_\n" foreach (@list);
}
exit($retval);
}
#------------------------
# where we wrap the Getopt::Long and resolve which arguments
# work and play well with other command line arguments.
#
# <editorialize on the what this version does or does not do
#
sub parse_cmd_line_options
{
my $ref = {}; $ref->{'delete'} = [];
#
# more editorializing
#
$ref->{'add'} = [] ; #
# this also doubles as the flash guide. in Usage
#
my @list = qw/
file|f=s
import|init|i
installdb
export|x|e
compact|c
delete|d=s
add|a=s
fsck
nup
kadb
help|h|?/; my @config_args = qw/bundling/;
Getopt::Long::Configure(@config_args);my $results = GetOptions($ref, @list) ;
Usage('Problem with Input Arguments',1,@list) unless ($results);
Usage('The General Help',0,@list) if ($ref->{'help'});
#
# now to create the action station section
# #sort out other gory details about the which arguments
#should or should not be dealt with$ref ;
} # end of parse_cmd_line_options
This dog has soldiered on in one variant or another...
vladimir: 41:] ./db_tool.plx --kadb
option: help
we have the following options:
add [sysname config_host] -> add sysname and config_host to db
delete [sysname ] -> delete sysname from db
show_sysnames -> list current sysnames in db
config_host -> get config_host for sysname in db
export -> export db to file
import -> import file to db
q|exit|quit -> exit kadboption: q exiting vladimir: 42:]
the '--kadb' started out as a bad JOKE, I whined at myMostGloriousLeader that just for him, I would offer up a 'kryptic command line interface with short and arcane syntax, you know, just like kadb....' IT HURTS when one stops laughing and has to implement it in a rush because, well, one just needs it down and dirty, but it has to work...
I went with the 'bundling' approach so that the 'oldGuy' *nix freaks would be 'happy' while the gnuSters would be able to wander the plains with their --help and the like...
ciao drieux
---
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
