query-rc learns '-q' option

This commit is contained in:
Sitaram Chamarty 2012-03-23 06:37:44 +05:30
parent e9ea674be9
commit 14e1354433

View file

@ -129,6 +129,7 @@ sub glrc {
my $all = 0; my $all = 0;
my $nonl = 0; my $nonl = 0;
my $quiet = 0;
sub query_rc { sub query_rc {
@ -144,7 +145,7 @@ sub query_rc {
} }
my @res = map { $rc{$_} } grep { $rc{$_} } @vars; my @res = map { $rc{$_} } grep { $rc{$_} } @vars;
print join( "\t", @res ) . ( $nonl ? '' : "\n" ) if @res; print join( "\t", @res ) . ( $nonl ? '' : "\n" ) if not $quiet and @res;
# shell truth # shell truth
exit 0 if @res; exit 0 if @res;
exit 1; exit 1;
@ -192,6 +193,7 @@ Usage: gitolite query-rc -a
-a print all variables and values -a print all variables and values
-n do not append a newline -n do not append a newline
-q exit code only (shell truth; 0 is success)
Example: Example:
@ -200,6 +202,8 @@ Example:
gitolite query-rc -a gitolite query-rc -a
# prints all known variables and values, one per line # prints all known variables and values, one per line
Note: '-q' is best used with only one variable.
=cut =cut
sub args { sub args {
@ -208,10 +212,11 @@ sub args {
GetOptions( GetOptions(
'all|a' => \$all, 'all|a' => \$all,
'nonl|n' => \$nonl, 'nonl|n' => \$nonl,
'quiet|q' => \$quiet,
'help|h' => \$help, 'help|h' => \$help,
) or usage(); ) or usage();
usage("'-a' cannot be combined with other arguments") if $all and @ARGV; usage("'-a' cannot be combined with other arguments or options") if $all and ( @ARGV or $nonl or $quiet );
usage() if not $all and not @ARGV or $help; usage() if not $all and not @ARGV or $help;
return @ARGV; return @ARGV;
} }