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

@ -57,7 +57,7 @@ my $current_data_version = "3.0";
my $rc = glrc('filename'); my $rc = glrc('filename');
do $rc if -r $rc; do $rc if -r $rc;
if (defined($GL_ADMINDIR)) { if ( defined($GL_ADMINDIR) ) {
say2 ""; say2 "";
say2 "FATAL: $rc seems to be for older gitolite; checking compat"; say2 "FATAL: $rc seems to be for older gitolite; checking compat";
require Gitolite::Compat; require Gitolite::Compat;
@ -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;
} }