Skip to content

Commit

Permalink
Issue RotherOSS#12: Added the option -cpanfile
Browse files Browse the repository at this point in the history
  • Loading branch information
bschmalhofer committed May 8, 2020
1 parent a7e1135 commit e72218b
Showing 1 changed file with 34 additions and 16 deletions.
50 changes: 34 additions & 16 deletions bin/otobo.CheckModules.pl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

use strict;
use warnings;
use feature qw(say);

use File::Basename;
use FindBin qw($RealBin);
Expand Down Expand Up @@ -111,30 +112,38 @@
$OSDist = $^O;
}

my $AllModules;
my $PackageList;
my $PrintAllModules;
my $PrintPackageList;
my $PrintCpanfile;
my $Help;
GetOptions(
all => \$AllModules,
list => \$PackageList,
h => \$Help
all => \$PrintAllModules,
list => \$PrintPackageList,
cpanfile => \$PrintCpanfile,
h => \$Help
);

# check needed params
if ($Help) {
print "\nReturn all required and optional packages of OTOBO.\n\n";
print "\n";
print "Return all required and optional packages of OTOBO.\n";
print "\n";
print "Usage:\n";
print " otobo.CheckModules.pl [-list|all]\n\n";
print " otobo.CheckModules.pl [-list|-cpanfile|-all]\n";
print "\n";
print "Options:\n";
printf " %-22s - %s", '[-list]', 'Return an install command with all required packages.' . "\n";
printf " %-22s - %s", '[-all]', 'Return all required, optional and bundled packages of OTOBO.' . "\n\n";
printf " %-22s - %s\n", '[-list]', 'Return an install command with all required packages that are missing.';
printf " %-22s - %s\n", '[-cpanfile]', 'Return a cpanfile with the required modules that are missing.';
printf " %-22s - %s\n", '[-all]', 'Return all required, optional and bundled packages of OTOBO.';
print "\n";

exit 1;
}

my $Options = shift || '';
my $NoColors;

if ( $ENV{nocolors} || $Options =~ m{\A nocolors}msxi ) {
if ( $PrintCpanfile || $ENV{nocolors} || $Options =~ m{\A nocolors}msxi ) {
$NoColors = 1;
}

Expand Down Expand Up @@ -594,10 +603,10 @@
},
);

if ($PackageList) {
if ($PrintCpanfile || $PrintPackageList) {
my %PackageList = _PackageList( \@NeededModules );

if ( IsArrayRefWithData( $PackageList{Packages} ) ) {
if ( $PrintPackageList && IsArrayRefWithData( $PackageList{Packages} ) ) {

my $CMD = $PackageList{CMD};

Expand All @@ -609,6 +618,12 @@
printf $CMD, join( ' ', @{ $PackageList{Packages} } );
print "\n";
}

if ( $PrintCpanfile && IsArrayRefWithData( $PackageList{MissingModules} ) ) {
for my $Module ( @{ $PackageList{MissingModules} } ) {
say "requires '$Module->{Module}';";
}
}
}
else {
# try to determine module version number
Expand All @@ -618,7 +633,7 @@
_Check( $Module, $Depends, $NoColors );
}

if ($AllModules) {
if ($PrintAllModules) {
print "\nBundled modules:\n\n";

my %PerlInfo = Kernel::System::Environment->PerlInfoGet(
Expand Down Expand Up @@ -807,6 +822,7 @@ sub _PackageList {
my $CMD;
my $SubCMD;
my @Packages;
my @MissingModules;

# if we're on Windows we don't need to see Apache + mod_perl modules
MODULE:
Expand Down Expand Up @@ -837,13 +853,15 @@ sub _PackageList {
$CMD = $InstallCommand{CMD};
$SubCMD = $InstallCommand{SubCMD};
push @Packages, $InstallCommand{Package};
push @MissingModules, $Module;
}
}

return (
CMD => $CMD,
SubCMD => $SubCMD,
Packages => \@Packages,
CMD => $CMD,
SubCMD => $SubCMD,
Packages => \@Packages,
MissingModules => \@MissingModules,
);
}

Expand Down

0 comments on commit e72218b

Please sign in to comment.