queryrc.pm rolled into rc.pm, removed

This commit is contained in:
Sitaram Chamarty 2012-03-09 06:22:01 +05:30
parent 8ffc5307d6
commit b89ac4dd1e
3 changed files with 63 additions and 83 deletions

View file

@ -1,81 +0,0 @@
package Gitolite::Commands::QueryRc;
# implements 'gitolite query-rc'
# ----------------------------------------------------------------------
=for usage
Usage: gitolite query-rc -a
gitolite query-rc <list of rc variables>
Example:
gitolite query-rc GL_ADMIN_BASE GL_UMASK
# prints "/home/git/.gitolite<tab>0077" or similar
gitolite query-rc -a
# prints all known variables and values, one per line
=cut
# ----------------------------------------------------------------------
@EXPORT = qw(
query_rc
);
use Exporter 'import';
use Getopt::Long;
use lib $ENV{GL_BINDIR};
use Gitolite::Rc;
use Gitolite::Common;
use strict;
use warnings;
# ----------------------------------------------------------------------
my $all = 0;
# ----------------------------------------------------------------------
sub query_rc {
trace( 1, "rc file not found; default should be " . glrc('default-filename') ) if not glrc('filename');
my @vars = args();
no strict 'refs';
if ( $vars[0] eq '-a' ) {
for my $e (@Gitolite::Rc::EXPORT) {
# perl-ism warning: if you don't do this the implicit aliasing
# screws up Rc's EXPORT list
my $v = $e;
# we stop on the first non-$ var
last unless $v =~ s/^\$//;
print "$v=" . ( defined($$v) ? $$v : 'undef' ) . "\n";
}
}
our $GL_BINDIR = $ENV{GL_BINDIR};
print join( "\t", map { $$_ } grep { $$_ } @vars ) . "\n" if @vars;
}
# ----------------------------------------------------------------------
sub args {
my $help = 0;
GetOptions(
'all|a' => \$all,
'help|h' => \$help,
) or usage();
usage("'-a' cannot be combined with other arguments") if $all and @ARGV;
return '-a' if $all;
usage() if not @ARGV or $help;
return @ARGV;
}
1;

View file

@ -6,6 +6,7 @@ package Gitolite::Rc;
@EXPORT = qw( @EXPORT = qw(
%rc %rc
glrc glrc
query_rc
$ADC_CMD_ARGS_PATT $ADC_CMD_ARGS_PATT
$REF_OR_FILENAME_PATT $REF_OR_FILENAME_PATT
@ -15,10 +16,17 @@ package Gitolite::Rc;
); );
use Exporter 'import'; use Exporter 'import';
use Getopt::Long;
use lib $ENV{GL_BINDIR}; use lib $ENV{GL_BINDIR};
use Gitolite::Common; use Gitolite::Common;
# ----------------------------------------------------------------------
our %rc;
# ----------------------------------------------------------------------
# variables that are/could be/should be in the rc file # variables that are/could be/should be in the rc file
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
@ -86,6 +94,61 @@ sub glrc {
} }
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# implements 'gitolite query-rc'
# ----------------------------------------------------------------------
=for usage
Usage: gitolite query-rc -a
gitolite query-rc <list of rc variables>
Example:
gitolite query-rc GL_ADMIN_BASE GL_UMASK
# prints "/home/git/.gitolite<tab>0077" or similar
gitolite query-rc -a
# prints all known variables and values, one per line
=cut
# ----------------------------------------------------------------------
my $all = 0;
sub query_rc {
trace( 1, "rc file not found; default should be " . glrc('default-filename') ) if not glrc('filename');
my @vars = args();
no strict 'refs';
if ( $vars[0] eq '-a' ) {
for my $e (sort keys %rc) {
print "$e=" . ( defined($rc{$e}) ? $rc{$e} : 'undef' ) . "\n";
}
return;
}
our $GL_BINDIR = $ENV{GL_BINDIR};
print join( "\t", map { $rc{$_} } @vars ) . "\n" if @vars;
}
# ----------------------------------------------------------------------
sub args {
my $help = 0;
GetOptions(
'all|a' => \$all,
'help|h' => \$help,
) or usage();
usage("'-a' cannot be combined with other arguments") if $all and @ARGV;
return '-a' if $all;
usage() if not @ARGV or $help;
return @ARGV;
}
1; 1;

View file

@ -59,8 +59,6 @@ sub args {
compile(); compile();
} elsif ( $command eq 'query-rc' ) { } elsif ( $command eq 'query-rc' ) {
shift @ARGV; shift @ARGV;
require Gitolite::Commands::QueryRc;
Gitolite::Commands::QueryRc->import;
query_rc(); query_rc();
} elsif ( $command eq 'list-groups' ) { } elsif ( $command eq 'list-groups' ) {
shift @ARGV; shift @ARGV;