Adapt modulemanager for the API added in the previous commit.

This commit is contained in:
Peter Powell 2017-03-24 23:20:28 +00:00
parent b6a69e98ee
commit 5ac5440a44

View File

@ -39,6 +39,7 @@ use FindBin qw($RealDir);
use lib $RealDir; use lib $RealDir;
use make::common; use make::common;
use make::console;
my %installed; my %installed;
# $installed{name} = $version # $installed{name} = $version
@ -252,9 +253,7 @@ sub resolve_deps {
} }
} }
my $action = $#ARGV >= 0 ? lc shift @ARGV : 'help'; command 'install', 'Install a third-party module', sub {
if ($action eq 'install') {
for my $mod (@ARGV) { for my $mod (@ARGV) {
my $vers = $mod =~ s/=([-0-9.]+)// ? $1 : undef; my $vers = $mod =~ s/=([-0-9.]+)// ? $1 : undef;
$mod = lc $mod; $mod = lc $mod;
@ -269,7 +268,9 @@ if ($action eq 'install') {
} }
$todo{$mod} = $ver; $todo{$mod} = $ver;
} }
} elsif ($action eq 'upgrade') { };
command 'upgrade', 'Upgrade a third-party module', sub {
my @installed = sort keys %installed; my @installed = sort keys %installed;
for my $mod (@installed) { for my $mod (@installed) {
next unless $mod =~ /^m_/; next unless $mod =~ /^m_/;
@ -279,7 +280,9 @@ if ($action eq 'install') {
%todo = %saved; %todo = %saved;
} }
} }
} elsif ($action eq 'list') { };
command 'list', 'List available third-party modules', sub {
my @all = sort keys %modules; my @all = sort keys %modules;
for my $mod (@all) { for my $mod (@all) {
my @vers = sort { ver_cmp() } keys %{$modules{$mod}}; my @vers = sort { ver_cmp() } keys %{$modules{$mod}};
@ -293,25 +296,15 @@ if ($action eq 'install') {
my $vers = join ' ', map { $_ eq $instver ? "\e[1m$_\e[m" : $_ } @vers; my $vers = join ' ', map { $_ eq $instver ? "\e[1m$_\e[m" : $_ } @vers;
print "$mod ($vers) - $desc\n"; print "$mod ($vers) - $desc\n";
} }
} else { };
print <<ENDUSAGE
Use: $0 <action> <args>
Action is one of the following
install install new modules
upgrade upgrade installed modules
list lists available modules
For installing a package, specify its name or name=version to force the execute_command @ARGV;
installation of a specific version.
ENDUSAGE
;exit 1;
}
resolve_deps(0); resolve_deps(0);
$| = 1; # immediate print of lines without \n $| = 1; # immediate print of lines without \n
print "Processing changes for $action...\n"; print "Processing changes...\n";
for my $mod (keys %installed) { for my $mod (keys %installed) {
next if $todo{$mod}; next if $todo{$mod};
print "Uninstalling $mod $installed{$mod}\n"; print "Uninstalling $mod $installed{$mod}\n";