Bug 16187: accept --verbose and -h
[koha.git] / koha_perl_deps.pl
blob9ca2a14cdb3f1a860d97ad637a49a6fdfcd01eb8
1 #!/usr/bin/perl
3 use Getopt::Long;
4 use Pod::Usage;
5 use Term::ANSIColor;
6 use FindBin; # we need to enforce which C4::Installer is used in case more than one is installed
8 use lib $FindBin::Bin;
10 use C4::Installer::PerlModules;
12 use strict;
13 use warnings;
15 my $help = 0;
16 my $missing = 0;
17 my $installed = 0;
18 my $upgrade = 0;
19 my $all = 0;
20 my $color = 0;
21 my $brief = 0;
22 my $req = 0;
24 GetOptions(
25 'h|help|?' => \$help,
26 'm|missing' => \$missing,
27 'i|installed' => \$installed,
28 'u|upgrade' => \$upgrade,
29 'a|all' => \$all,
30 'b|brief' => \$brief,
31 'r|required' => \$req,
32 'c|color' => \$color,
35 pod2usage(1) if $help || (!$missing && !$installed && !$upgrade && !$all);
37 my $koha_pm = C4::Installer::PerlModules->new;
38 $koha_pm->versions_info;
40 my @pm = ();
42 push @pm, 'missing_pm' if $missing || $all;
43 push @pm, 'upgrade_pm' if $upgrade || $all;
44 push @pm, 'current_pm' if $installed || $all;
46 if (!$brief) {
47 print color 'bold blue' if $color;
48 print"
49 Installed Required Module is
50 Module Name Version Version Required
51 --------------------------------------------------------------------------------------------
55 my $count = 0;
56 foreach my $type (@pm) {
57 my $mod_type = $type;
58 $mod_type =~ s/_pm$//;
59 my $pm = $koha_pm->get_attr($type);
60 foreach (@$pm) {
61 foreach my $pm (keys(%$_)) {
62 print color 'yellow' if $type eq 'upgrade_pm' && $color;
63 print color 'red' if $type eq 'missing_pm' && $color;
64 print color 'green' if $type eq 'current_pm' && $color;
65 my $required = ($_->{$pm}->{'required'}?'Yes':'No');
66 my $current_version = ($color ? $_->{$pm}->{'cur_ver'} :
67 $type eq 'missing_pm' || $type eq 'upgrade_pm' ? $_->{$pm}->{'cur_ver'}." *" : $_->{$pm}->{'cur_ver'});
68 if (!$brief) {
69 if (($req && $required eq 'Yes') || !$req) {
70 format =
71 @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<
72 $pm, $current_version, $_->{$pm}->{'min_ver'}, $required
74 write;
75 $count++;
78 else {
79 if (($req && $required eq 'Yes') || !$req) {
80 print "$pm\n";
81 $count++;
88 if (!$brief) {
89 print color 'bold blue' if $color;
90 my $footer = "
91 --------------------------------------------------------------------------------------------
92 Total modules reported: $count ";
94 if ($color) {
95 $footer .= "\n\n";
97 else {
98 $footer .= "* Module is missing or requires an upgrade.\n\n";
101 print $footer;
102 print color 'reset' if $color;
107 __END__
109 =head1 NAME
111 koha_perl_deps.pl
113 =head1 SYNOPSIS
115 At least one of -a, -m, -i, or -u flags must specified to not trigger help.
116 ./koha_perl_deps.pl -m [-b] [-r] [-c]
117 ./koha_perl_deps.pl -u [-b] [-r] [-c]
118 ./koha_perl_deps.pl -i [-b] [-r] [-c]
119 ./koha_perl_deps.pl -a [-b] [-r] [-c]
120 ./koha_perl_deps.pl [-[h?]]
122 =head1 OPTIONS
124 =over 8
126 =item B<-m|--missing>
128 lists all missing perl modules
130 =item B<-i|--installed>
132 lists all installed perl modules
134 =item B<-u|--upgrade>
136 lists all perl modules needing to be upgraded relative to Koha
138 =item B<-a|--all>
140 lists all koha perl dependencies
141 This is equivalent to '-m -i -u'.
143 =item B<-b|--brief>
145 lists only the perl dependency name.
147 =item B<-r|--required>
149 filters list to only required perl dependencies.
151 =item B<-c|--color>
153 formats the output in color; red = module is missing, yellow = module requires upgrading, green = module is installed and current
155 =item B<-h|--help|?>
157 prints this help text
159 =back
161 =head1 AUTHOR
163 Chris Nighswonger <cnighswonger AT foundations DOT edu>
165 =head1 COPYRIGHT
167 Copyright 2010 Foundations Bible College.
169 =head1 LICENSE
171 This file is part of Koha.
173 Koha is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
174 Foundation; either version 2 of the License, or (at your option) any later version.
176 You should have received a copy of the GNU General Public License along
177 with Koha; if not, write to the Free Software Foundation, Inc.,
178 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
180 =head1 DISCLAIMER OF WARRANTY
182 Koha is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
183 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
185 =cut