-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtbUse.m
63 lines (52 loc) · 1.77 KB
/
tbUse.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
function results = tbUse(registered, varargin)
% Deploy registered toolboxes by name.
%
% The goal here is to make it a one-liner to fetch toolboxes that are
% registerd on ToolboxHub and add them to the Matlab path. This should
% automate several steps that we usually do by hand, which is good for
% consistency and convenience.
%
% This function uses ToolboxToolbox shared parameters and preferences. See
% tbParsePrefs().
%
% results = tbUse('foo') fetches one toolbox named 'foo' from ToolboxHub
% and adds it to the Matlab path.
%
% results = tbUse({'foo', 'bar', ...}) fetches toolboxes named
% 'foo', 'bar', etc. from ToolboxHub and adds them to the matlab path.
%
% 2016 [email protected]
persistentPrefs = tbGetPersistentPrefs;
prefs = tbParsePrefs(persistentPrefs, varargin{:});
parser = inputParser();
parser.addRequired('registered', @(r) ischar(r) || iscellstr(r) || isstring(r));
parser.parse(registered);
registered = parser.Results.registered;
if isstring(registered)
registered = registered.cellstr;
end
% convert convenient string form to general list form
if ischar(registered)
registered = {registered};
end
[results, included] = tbDeployToolboxes(persistentPrefs, prefs, 'registered', registered);
% "included" is populated even if "results" is empty due to onlyOnce==true
cdToFolder(included(1), prefs.cdToFolder)
function cdToFolder(result, paramCdToFolder)
toolboxRoot = tbLocateToolbox(result.name);
specified = result.cdToFolder;
switch paramCdToFolder
case true
fdr = fullfile(toolboxRoot, specified);
case false
fdr = [];
case 'as-specified'
if isempty(specified)
fdr = [];
else
fdr = fullfile(toolboxRoot, specified);
end
end
if ~isempty(fdr)
cd(fdr)
end