verbose/quiet options

--HG--
branch : pmacs2
This commit is contained in:
moculus 2008-05-19 14:51:10 +00:00
parent aa2eb9e9fb
commit a8b290434f
1 changed files with 9 additions and 2 deletions

View File

@ -30,8 +30,10 @@ sub usage {
usage: $prog [options] usage: $prog [options]
-h,--help show this message -h,--help show this message
-e,--eval STR eval STR before interaction -e,--eval STR eval STR before interaction
-p,--pipe run in pipe mode (as a subprocess) -p,--pipe run in pipe mode
-q,--quiet hide undef eval output
-r,--run PATH run PATH before interaction -r,--run PATH run PATH before interaction
-v,--verbose output all eval results (default)
perl needs a good interpreter. perl needs a good interpreter.
EOT EOT
@ -243,6 +245,7 @@ sub main {
my ($prompt1, $prompt2) = ("\001\033[24m\002>>>", "\001\033[24m\002..>"); my ($prompt1, $prompt2) = ("\001\033[24m\002>>>", "\001\033[24m\002..>");
# process the arguments provided; save original @ARGV for use later # process the arguments provided; save original @ARGV for use later
my $quiet;
my @preload; my @preload;
my @oldargv = @ARGV; my @oldargv = @ARGV;
Getopt::Long::GetOptions( Getopt::Long::GetOptions(
@ -251,6 +254,8 @@ sub main {
'pipe|p' => sub { $pipe = 'line' }, 'pipe|p' => sub { $pipe = 'line' },
'run|r=s' => sub { push(@preload, ['run', $_[1]]); }, 'run|r=s' => sub { push(@preload, ['run', $_[1]]); },
'use|u=s' => sub { push(@preload, ['use', $_[1]]); }, 'use|u=s' => sub { push(@preload, ['use', $_[1]]); },
'quiet|q' => sub { $quiet = 1; },
'verbose|v' => sub { $quiet = undef; },
) || usage(1); ) || usage(1);
# let's display a nice banner to the user # let's display a nice banner to the user
@ -355,7 +360,9 @@ sub main {
print $@; print $@;
} elsif(scalar(@results) == 0) { } elsif(scalar(@results) == 0) {
} elsif(scalar(@results) == 1) { } elsif(scalar(@results) == 1) {
print $results[0] . "\n" unless $results[0] eq 'undef'; if(!$quiet || $results[0] ne 'undef') {
print $results[0] . "\n";
}
} else { } else {
print join(", ", @results) . "\n"; print join(", ", @results) . "\n";
} }