1 |
commit: cb988b42b74fc9a5b4715df7122db7eb01d3e4ba |
2 |
Author: Kent Fredric <kentfredric <AT> gmail <DOT> com> |
3 |
AuthorDate: Tue Feb 28 21:46:55 2012 +0000 |
4 |
Commit: Kent Fredric <kentfredric <AT> gmail <DOT> com> |
5 |
CommitDate: Tue Feb 28 21:46:55 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/perl-overlay.git;a=commit;h=cb988b42 |
7 |
|
8 |
[scripts/package_log.pl] update to use optparser , fix bug that was preventing specifiying multiple packages |
9 |
|
10 |
--- |
11 |
scripts/package_log.pl | 78 ++++++++++++++++++++++------------------------- |
12 |
1 files changed, 37 insertions(+), 41 deletions(-) |
13 |
|
14 |
diff --git a/scripts/package_log.pl b/scripts/package_log.pl |
15 |
index 22e571d..dc1a877 100755 |
16 |
--- a/scripts/package_log.pl |
17 |
+++ b/scripts/package_log.pl |
18 |
@@ -14,6 +14,7 @@ use env::gentoo::perl_experimental; |
19 |
use metacpan qw( mcpan ); |
20 |
use Term::ANSIColor qw( :constants ); |
21 |
use Try::Tiny; |
22 |
+use optparse; |
23 |
use coloriterator |
24 |
coloriser => { -as => 'author_colour' }, |
25 |
coloriser => { -as => 'dist_colour' }; |
26 |
@@ -34,20 +35,10 @@ use coloriterator |
27 |
# * CPAN::Changes |
28 |
# |
29 |
|
30 |
-my $flags; |
31 |
-my $singleflags; |
32 |
- |
33 |
-@ARGV = grep { defined } map { |
34 |
- $_ =~ /^--(\w+)/ |
35 |
- ? do { $flags->{$1}++; undef } |
36 |
- : do { |
37 |
- $_ =~ /^-(\w+)/ |
38 |
- ? do { $singleflags->{$1}++; undef } |
39 |
- : do { $_ } |
40 |
- } |
41 |
-} @ARGV; |
42 |
- |
43 |
-if ( $flags->{help} or $singleflags->{h} ) { print help(); exit 0; } |
44 |
+my $optparse = optparse->new( |
45 |
+ argv => \@ARGV, |
46 |
+ help => sub { print help(); }, |
47 |
+); |
48 |
|
49 |
my $oldest_date = '2011-10-01T00:00:00.000Z'; |
50 |
my $newest_date = '2012-02-01T00:00:00.000Z'; |
51 |
@@ -56,46 +47,51 @@ my $search = {}; |
52 |
|
53 |
my $and = []; |
54 |
|
55 |
-if ( not $flags->{all} ) { |
56 |
- push @{$and}, { |
57 |
- range => { |
58 |
- date => { |
59 |
- from => $oldest_date, |
60 |
- #to => $newest_date, |
61 |
- } |
62 |
- } |
63 |
- }; |
64 |
-} |
65 |
+if ( not $optparse->long_opts->{all} ) { |
66 |
+ push @{$and}, { |
67 |
+ range => { |
68 |
+ date => { |
69 |
+ from => $oldest_date, |
70 |
|
71 |
-push @{$and} , { |
72 |
- term => { |
73 |
- 'distribution' => @ARGV, |
74 |
-# minimum_match => 1, |
75 |
+ #to => $newest_date, |
76 |
+ } |
77 |
} |
78 |
-}; |
79 |
+ }; |
80 |
+} |
81 |
+ |
82 |
+#my $or = []; |
83 |
|
84 |
-$search->{query} = { |
85 |
- constant_score => { |
86 |
- filter => { |
87 |
- and => $and, |
88 |
- } |
89 |
- } |
90 |
+#for my $dist ( @{ $optparse->extra_opts } ) { |
91 |
+ |
92 |
+push @{$and}, { |
93 |
+ terms => { |
94 |
+ 'distribution' => $optparse->extra_opts, |
95 |
+ |
96 |
+ # minimum_match => 1, |
97 |
+ } |
98 |
}; |
99 |
|
100 |
+#} |
101 |
+ |
102 |
+#push @{$and}, { |
103 |
+# or => $or, |
104 |
+#}; |
105 |
+ |
106 |
+$search->{query} = { constant_score => { filter => { and => $and, } } }; |
107 |
+ |
108 |
$search->{sort} = [ |
109 |
|
110 |
# { 'author' => 'asc', }, |
111 |
{ 'date' => 'desc', }, |
112 |
]; |
113 |
-$search->{size} = 10; |
114 |
+$search->{size} = 10000; |
115 |
|
116 |
$search->{fields} = [qw( author name date distribution version )]; |
117 |
|
118 |
-if ( $flags->{deps} ) { |
119 |
+if ( $optparse->long_opts->{deps} ) { |
120 |
push @{ $search->{fields} }, '_source.dependency'; |
121 |
} |
122 |
|
123 |
- |
124 |
_log( ['initialized: fetching search results'] ); |
125 |
|
126 |
my $results = mcpan->post( 'release/_search', $search ); |
127 |
@@ -106,7 +102,7 @@ for my $result ( @{ $results->{hits}->{hits} } ) { |
128 |
|
129 |
# use Data::Dump qw(pp); |
130 |
# pp $result; |
131 |
- say $_ for format_result( $result->{fields}, $flags ); |
132 |
+ say $_ for format_result( $result->{fields}, $optparse->long_opts ); |
133 |
} |
134 |
|
135 |
exit 0; |
136 |
@@ -119,7 +115,7 @@ sub pp { require Data::Dump; goto \&Data::Dump::pp } |
137 |
sub gv { require Gentoo::PerlMod::Version; goto \&Gentoo::PerlMod::Version::gentooize_version } |
138 |
|
139 |
sub _log { |
140 |
- return unless $flags->{trace}; |
141 |
+ return unless $optparse->long_opts->{trace}; |
142 |
return *STDERR->print(@_) if ( not ref $_[0] ); |
143 |
|
144 |
state $prefix = "\e[7m* package_log.pl:\e[0m "; |
145 |
@@ -213,7 +209,7 @@ sub change_for { |
146 |
|
147 |
return unless $file; |
148 |
|
149 |
- if ( $flags->{'nosummarize'} ) { |
150 |
+ if ( $optparse->long_opts->{'nosummarize'} ) { |
151 |
return $file; |
152 |
} |