Posted on 2010-03-02 13:05:39.995894-08 by kmahler
Some suggestions for improvement

Hi,


First of all, I would like to thank you for providing this great package. It is very useful when developing perl scripts in an global engineering development environment, especially when the complexity of the script is high and there are many users.


Since my IT installation does not include GetOpt::Declare, I downloaded it to a local area and made custom changes.


Here are my suggestions for improvement (I actually made these changes and have been running with them for some time).


1) Allow 'help' to be present anywhere within the command; not just by itself.


When a script has many arguments and you start typing them on the command line and then you forget one, it's nice to just type -help and hit enter, look at the help, retrieve the last command (with the -help), backspace over the -help and finish entering the arguments.


It seems that Getopt::Declare only allows -help by itself.


2) Allow the parameter description to not be terminated by a blank line when displaying help info.


When the script contains arguments that need detailed explanations, this change allows those explanations to be presented in a more user-friendly readable format.


Here's an example argument:


-replace\t [required][requires: -dut && -tcf]


Replace the Test Bench components that are specified in the Testbench Configuration File (see '-tcf' argument below).


This argument causes tb_wizard to replace code between the XTL start tag and the XTL end tag that corresponds to each XTL Spec name/instance name pair specified in the Testbench Configuration File.


Care must be taken if you use this argument because if you have manually modified any code within these XTL tags, then it may potentially be lost.


Only use -replace rather than -reinstall when you 'know' that the the component does not contain any optimizable code.


You can use -replace to incrementally add components to you testbench, but remember that it will not optimize out any duplicate code (see -reinstall above).


-next_parm\t . . .


3) Enhance code to NOT suppress any text in square brackets (just the directives) when displaying help information.


If I have a description such as "my_script required_args [optional_args]" it suppresses the "[optional_args]".


4) Add a new [suppress_usage] directive to suppress displaying of usage info, since it is not accurate and developers may want to provide their own more detailed version. When this directive is enabled, the 'try $ltprogram_name> -help' message is also suppressed.


5) Fix code to recognize an invalid argument when the specified argument has one extra character appended to the end of a valid argument. This occurs when " [cluster:none]" and "[strict]" directives are specified.


For instance, if '-trace' is a valid parameter and '-tracez' was entered', then no error would be flagged.


With my fix below, if '-tracez' is entered, an error message is flagged, although not an appropriate one.


"Error: unrecognizable argument 'z'"


6) Fix code to recognize similar values for custom parameter types.


For instance, when the following lines are defined:


[pvtype: class_type /bus_master|bus_master_container|bus_master_descriptor/]


-class_type <type:class_type$gt


And this lined was entered:


-class_type bus_master_container


The code would match 'bus_master' and not 'bus_master_container' and thus '$parms->{-class_type}' would contain 'bus_master'.


7) Change error message when a parameter requires another parameter.


Original message was:


Error: parameter '-add' can only be specified with '-dut and -instance'


New message is:


Error: parameter '-add' requires '-dut and -instance'


The original message implies that '-add' can only be specified with '-dut and -instance', but in actuality it can be specified with '-foo_bar' too, although '-foo_bar' is optional.


8) Change error message when a parameter is missing its associated value.


Original message was:


Error: incorrect specification of '-add' parameter


New message is:


Error: No value or invalid value specified with '-add' parameter


9) Don't display 'unrecognizable argument' error messages if previous error messages have been encountered or at least have a directive to disable this.


10) Change code to NOT check for unrecognizable arguments when a previous error is encountered, since it would inadvertently recognize valid arguments as unrecognizable.


11) Remove '()' in error message when a parameter is unrecognized.


Original message was:


Error: unrecognizable argument ('-bad')


New message is:


Error: unrecognizable argument '-bad'


Here are the differences (diff) that I made versus version '1.11'.


=> diff Declare.pm Declare.pm_original 440c440 < $_errormsg = q|No value or invalid value specified with '# . $flag . q#' parameter| unless $_ +errormsg; --- > $_errormsg = q|incorrect specification of '# . $flag . q#' parameter| unless $_errormsg; 475c475 < $code .= '(\s|\0|\Z)/gx' . $nocase . ' or last;' --- > $code .= '/gx' . $nocase . ' or last;' 617d616 < my $_suppress_usage = 0; 671d669 < $_suppress_usage ||= $desc =~ /\Q[suppress_usage]/; 692d689 < $_suppress_usage ||= $decorator =~ /\Q[suppress_usage]/; 736d732 < suppress_usage => $_suppress_usage, 1075c1071 < $desc =~ s/^\s*\[.*?\]\s*\n/\n/gm; --- > $desc =~ s/^\s*\[.*?\]\s*\n//gm; 1081c1077 < { $lastdesc = $desc; } --- > { next; } 1097,1116c1093,1095 < < #------------------------------------------------------------------------- < # Suppress the output of all directives. < #------------------------------------------------------------------------- < $desc =~ s/\[\s*cluster:[^\]]+\]//gi; < $desc =~ s/\[\s*pvtype:[^\]]+\]//gi; < $desc =~ s/\[\s*mutex:[^\]]+\]//gi; < $desc =~ s/\[\s*excludes:[^\]]+\]//gi; < $desc =~ s/\[\s*requires:[^\]]+\]//gi; < < $desc =~ s/\[\s*strict\s*\]//gi; < $desc =~ s/\[\s*suppress_usage\s*\]//gi; < $desc =~ s/\[\s*ditto\s*\]//gi; < $desc =~ s/\[\s*no\s*case\s*\]//gi; < $desc =~ s/\[\s*required\s*\]//gi; < $desc =~ s/\[\s*repeatable\s*\]//gi; < $desc =~ s/\[\s*undocumented\s*\]//gi; < < $decfirst = 1 unless defined $decfirst; < --- > $desc =~ s/\[.*?\]//g; > $decfirst = 1 unless defined $decfirst > or $desc =~ m/\A\s*\Z/; 1145,1152c1124,1125 < #----------------------------------------------------------------------------- < # If the [suppress_usage] directive is NOT enabled AND the source of the < # arguments is NOT from the command line (i.e. not from ARGV), then display < # the usage information. < #----------------------------------------------------------------------------- < if ( !$self->{_internal}{suppress_usage} < and < !$self->{_internal}{source} ) { --- > unless ($self->{_internal}{source}) > { 1158,1159c1131 < < print $PAGER "Options:\n" unless ($decfirst or $self->{_internal}{suppress_usage}); --- > print $PAGER "Options:\n" unless $decfirst; 1264c1236 < pos $_args = $_nextpos+length($_lastprefix)-1; --- > pos $_args = $_nextpos+length($_lastprefix); 1311c1283 < . q#' requires '# . _enbool($arg->{requires}) --- > . q#' can only be specified with '# . _enbool($arg->{requires}) 1327d1298 < if ($_errors == 0) { 1331c1302 < print STDERR "Error"."$self->{_internal}{source}: unrecognizable argument '$_'\n"; --- > print STDERR "Error"."$self->{_internal}{source}: unrecognizable argument ('$_')\n"; 1334d1304 < } 1341,1342c1311 < if ($_errors && !$self->{_internal}{source} < && !$self->{_internal}{suppress_usage}) --- > if ($_errors && !$self->{_internal}{source})


Thanks,


Ken Mahler


Mr_Verification, LLC

1111 Ritter Drive

Cedar Park, TX 78613

Mr_Verification@ieee.org

Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.