Skip to content

Commit

Permalink
added mpm freeze, fixes #36
Browse files Browse the repository at this point in the history
  • Loading branch information
mobeets committed Nov 9, 2017
1 parent e26ea42 commit cf54bd9
Showing 1 changed file with 48 additions and 5 deletions.
53 changes: 48 additions & 5 deletions mpm.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function mpm(action, varargin)
% - install: installs a package by name
% - uninstall: installs a package by name
% - search: finds a url for a package by name (searches Github and
% - freeze: list all installed packages (optional: in installdir)
% File Exchange)
% name [optional]: name of package (e.g., 'matlab2tikz')
%
Expand Down Expand Up @@ -44,20 +45,27 @@ function mpm(action, varargin)
% load metadata
[opts.metadata, opts.metafile] = getMetadata(opts);

% init paths
% mpm init
if strcmpi(opts.action, 'init')
opts.update_mpm_paths = true;
pkg.addpath = false; % ignore dummy pkg
updatePaths(pkg, opts);
return;
end

% mpm freeze
if strcmpi(opts.action, 'freeze')
listPackages(opts);
return;
end

% mpm uninstall
if strcmpi(opts.action, 'uninstall')
removePackage(pkg, opts);
return;
end

% handle package
% mpm search OR mpm install
findAndSetupPackage(pkg, opts);
end

Expand Down Expand Up @@ -136,10 +144,28 @@ function removePackage(pkg, opts)
disp('Uninstallation complete.');
end

function listPackages(opts)
pkgs = opts.metadata.packages;
if isempty(pkgs)
disp(['No packages currently installed to ' opts.installdir]);
return;
end
disp(['Packages currently installed to ' opts.installdir ':']);
for ii = 1:numel(pkgs)
pkg = pkgs(ii);
nm = pkg.name;
if ~isempty(pkg.release_tag)
nm = [nm '==' pkg.release_tag];
end
disp(['- ' nm]);
end
end

function [pkg, opts] = setDefaultOpts()
% load opts from config file, and then set additional defaults

% empty package
pkg.name = '';
pkg.url = '';
pkg.internaldir = '';
pkg.release_tag = '';
Expand Down Expand Up @@ -469,7 +495,7 @@ function updatePaths(pkg, opts)

% init matlab's input parser and read action
q = inputParser;
validActions = {'install', 'search', 'uninstall', 'init'};
validActions = {'install', 'search', 'uninstall', 'init', 'freeze'};
checkAction = @(x) any(validatestring(x, validActions));
addRequired(q, 'action', checkAction);
defaultName = '';
Expand All @@ -491,7 +517,11 @@ function updatePaths(pkg, opts)

% no additional args
if numel(remainingArgs) == 0
error('You must specify a package name or a filename.');
if strcmpi(opts.action, 'freeze')
return;
else
error('You must specify a package name or a filename.');
end
end

% if first arg is not a param name, it's the package name
Expand Down Expand Up @@ -563,7 +593,9 @@ function updatePaths(pkg, opts)
return;
end
if isempty(pkg.name) && isempty(opts.infile)
error('You must specify a package name or a filename.');
if ~strcmpi(opts.action, 'freeze')
error('You must specify a package name or a filename.');
end
end
if ~isempty(opts.infile)
assert(isempty(pkg.name), ...
Expand All @@ -590,6 +622,17 @@ function updatePaths(pkg, opts)
if strcmpi(opts.action, 'search')
assert(~opts.force, 'Nothing to force when searching.');
end
if strcmpi(opts.action, 'freeze')
assert(~opts.force, 'Nothing to force when running ''freeze''.');
assert(isempty(pkg.url), ...
'Cannot specify url when running ''freeze''');
assert(isempty(pkg.internaldir), ...
'Cannot specify internaldir when running ''freeze''');
assert(isempty(pkg.release_tag), ...
'Cannot specify release_tag when running ''freeze''');
assert(~opts.searchgithubfirst, ...
'Cannot set searchgithubfirst when running ''freeze''');
end
end

function readRequirementsFile(fnm, opts)
Expand Down

0 comments on commit cf54bd9

Please sign in to comment.