aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin H. Johnson <robbat2@gentoo.org>2020-01-29 06:50:00 -0800
committerRobin H. Johnson <robbat2@gentoo.org>2020-01-29 06:56:28 -0800
commit976f4aa6d3e82e568149dd58a0197b36641b7b81 (patch)
tree5df93d3bd42ed5eebfce726bdf559d45d2684075 /contrib/console.pl
parentMerge remote-tracking branch 'origin/master' into bugstest (diff)
parentMerge tag 'release-5.0.6' into bugstest (diff)
downloadbugzilla-976f4aa6d3e82e568149dd58a0197b36641b7b81.tar.gz
bugzilla-976f4aa6d3e82e568149dd58a0197b36641b7b81.tar.bz2
bugzilla-976f4aa6d3e82e568149dd58a0197b36641b7b81.zip
Merge branch 'bugstest-5.0.6' into bugstest
Merge my 5.0.6 import changes. This is specifically a merge to make it easier to merge upstream changes again after the code reformatting. Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
Diffstat (limited to 'contrib/console.pl')
-rwxr-xr-xcontrib/console.pl159
1 files changed, 82 insertions, 77 deletions
diff --git a/contrib/console.pl b/contrib/console.pl
index fe2342cd9..7c1748064 100755
--- a/contrib/console.pl
+++ b/contrib/console.pl
@@ -20,115 +20,120 @@ use Bugzilla::Bug;
use Term::ReadLine;
use Data::Dumper;
$Data::Dumper::Sortkeys = 1;
-$Data::Dumper::Terse = 1;
-$Data::Dumper::Indent = 1;
-$Data::Dumper::Useqq = 1;
+$Data::Dumper::Terse = 1;
+$Data::Dumper::Indent = 1;
+$Data::Dumper::Useqq = 1;
$Data::Dumper::Maxdepth = 1;
-$Data::Dumper::Deparse = 0;
+$Data::Dumper::Deparse = 0;
my $sysname = get_text('term', {term => 'Bugzilla'});
-my $term = new Term::ReadLine "$sysname Console";
+my $term = new Term::ReadLine "$sysname Console";
read_history($term);
END { write_history($term) }
-while ( defined (my $input = $term->readline("$sysname> ")) ) {
- my @res = eval($input);
- if ($@) {
- warn $@;
- }
- else {
- print Dumper(@res);
- }
+while (defined(my $input = $term->readline("$sysname> "))) {
+ my @res = eval($input);
+ if ($@) {
+ warn $@;
+ }
+ else {
+ print Dumper(@res);
+ }
}
print STDERR "\n";
exit 0;
# d: full dump (normal behavior is limited to depth of 1)
sub d {
- local $Data::Dumper::Maxdepth = 0;
- local $Data::Dumper::Deparse = 1;
- print Dumper(@_);
- return ();
+ local $Data::Dumper::Maxdepth = 0;
+ local $Data::Dumper::Deparse = 1;
+ print Dumper(@_);
+ return ();
}
# p: print as a single string (normal behavior puts list items on separate lines)
sub p {
- no warnings; # suppress possible undefined var message
- print(@_, "\n");
- return ();
+ no warnings; # suppress possible undefined var message
+ print(@_, "\n");
+ return ();
}
sub filter {
- my $name = shift;
- my $filter = Bugzilla->template->{SERVICE}->{CONTEXT}->{CONFIG}->{FILTERS}->{$name};
- if (scalar @_) {
- return $filter->(@_);
- }
- else {
- return $filter;
- }
+ my $name = shift;
+ my $filter
+ = Bugzilla->template->{SERVICE}->{CONTEXT}->{CONFIG}->{FILTERS}->{$name};
+ if (scalar @_) {
+ return $filter->(@_);
+ }
+ else {
+ return $filter;
+ }
}
-sub b { get_object('Bugzilla::Bug', @_) }
-sub u { get_object('Bugzilla::User', @_) }
+sub b { get_object('Bugzilla::Bug', @_) }
+sub u { get_object('Bugzilla::User', @_) }
sub f { get_object('Bugzilla::Field', @_) }
sub get_object {
- my $class = shift;
- $_ = shift;
- my @results = ();
-
- if (ref $_ eq 'HASH' && keys %$_) {
- @results = @{$class->match($_)};
- }
- elsif (m/^\d+$/) {
- @results = ($class->new($_));
- }
- elsif (m/\w/i && grep {$_ eq 'name'} ($class->_get_db_columns)) {
- @results = @{$class->match({name => $_})};
- }
- else {
- @results = ();
- }
-
- if (wantarray) {
- return @results;
- }
- else {
- return shift @results;
- }
+ my $class = shift;
+ $_ = shift;
+ my @results = ();
+
+ if (ref $_ eq 'HASH' && keys %$_) {
+ @results = @{$class->match($_)};
+ }
+ elsif (m/^\d+$/) {
+ @results = ($class->new($_));
+ }
+ elsif (m/\w/i && grep { $_ eq 'name' } ($class->_get_db_columns)) {
+ @results = @{$class->match({name => $_})};
+ }
+ else {
+ @results = ();
+ }
+
+ if (wantarray) {
+ return @results;
+ }
+ else {
+ return shift @results;
+ }
}
sub read_history {
- my ($term) = @_;
-
- if (open HIST, "<$ENV{HOME}/.bugzilla_console_history") {
- foreach (<HIST>) {
- chomp;
- $term->addhistory($_);
- }
- close HIST;
+ my ($term) = @_;
+
+ if (open HIST, "<$ENV{HOME}/.bugzilla_console_history") {
+ foreach (<HIST>) {
+ chomp;
+ $term->addhistory($_);
}
+ close HIST;
+ }
}
sub write_history {
- my ($term) = @_;
-
- if ($term->can('GetHistory') && open HIST, ">$ENV{HOME}/.bugzilla_console_history") {
- my %seen_hist = ();
- my @hist = ();
- foreach my $line (reverse $term->GetHistory()) {
- next unless $line =~ m/\S/;
- next if $seen_hist{$line};
- $seen_hist{$line} = 1;
- push @hist, $line;
- last if (scalar @hist > 500);
- }
- foreach (reverse @hist) {
- print HIST $_, "\n";
- }
- close HIST;
+ my ($term) = @_;
+
+ if (
+ $term->can('GetHistory') && open HIST,
+ ">$ENV{HOME}/.bugzilla_console_history"
+ )
+ {
+ my %seen_hist = ();
+ my @hist = ();
+ foreach my $line (reverse $term->GetHistory()) {
+ next unless $line =~ m/\S/;
+ next if $seen_hist{$line};
+ $seen_hist{$line} = 1;
+ push @hist, $line;
+ last if (scalar @hist > 500);
+ }
+ foreach (reverse @hist) {
+ print HIST $_, "\n";
}
+ close HIST;
+ }
}
__END__