(minor) usage() sub can handle multiple usage sections in the same script

This commit is contained in:
Sitaram Chamarty 2012-03-12 10:43:33 +05:30
parent 84422ccf30
commit cbd4d43687

View file

@ -75,10 +75,12 @@ sub _die {
} }
sub usage { sub usage {
_warn(shift) if @_; my ($warn, $section) = @_;
_warn($warn) if $warn;
$section ||= 'usage';
my $scriptname = ( caller() )[1]; my $scriptname = ( caller() )[1];
my $script = slurp($scriptname); my $script = slurp($scriptname);
$script =~ /^=for usage(.*?)^=cut/sm; $script =~ /^=for $section(.*?)^=cut/sm;
say2( $1 ? $1 : "...no usage message in $scriptname" ); say2( $1 ? $1 : "...no usage message in $scriptname" );
exit 1; exit 1;
} }