changeset 30:d9f899b1dfd0

Add status command and make subpathIsActive a static method
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 18 Sep 2018 14:15:23 +0200
parents 91724783a931
children 769d1d252a3c
files +mpm/MatlabPathManager.m +mpm/status.m
diffstat 2 files changed, 40 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/+mpm/MatlabPathManager.m	Tue Sep 18 13:19:38 2018 +0200
+++ b/+mpm/MatlabPathManager.m	Tue Sep 18 14:15:23 2018 +0200
@@ -90,7 +90,7 @@
             sp = obj.projectSubpaths(projectFolder);
 
             for i = 1:length(sp)
-                if ~subpathIsActive(fullfile(projectFolder,sp{i}), mpath)
+                if ~obj.subpathIsActive(fullfile(projectFolder,sp{i}), mpath)
                     b = false;
                     return;
                 end
@@ -107,24 +107,26 @@
             end
         end
     end
-end
 
-% Test if the path p is active among folders in path with the same final foldername
-function b = subpathIsActive(p, paths)
-    pathparts = split(p, filesep);
-    foldername = pathparts{end};
+    methods (Static)
+        % Test if the path p is active among folders in path with the same final foldername
+        function b = subpathIsActive(p, paths)
+            pathparts = split(p, filesep);
+            foldername = pathparts{end};
 
-    for i = 1:length(paths)
-        if ~endsWith(paths{i}, foldername)
-            % Ignore files with different end foldername
-            continue
-        end
+            for i = 1:length(paths)
+                if ~endsWith(paths{i}, foldername)
+                    % Ignore files with different end foldername
+                    continue
+                end
 
-        b = strcmp(p, paths{i});
-        return
+                b = strcmp(p, paths{i});
+                return
+            end
+
+            b = false;
+        end
     end
-
-    b = false;
 end
 
 % TODO: Organize order of methods
--- a/+mpm/status.m	Tue Sep 18 13:19:38 2018 +0200
+++ b/+mpm/status.m	Tue Sep 18 14:15:23 2018 +0200
@@ -1,9 +1,28 @@
-function status()
+function status(projectFolder)
+    if ~exist('projectFolder', 'var') || isempty(projectFolder)
+        projectFolder = pwd;
+    end
+
     m = mpm.MatlabPathManager();
-    subpaths = m.loadedSubpaths();
+    loaded = m.loadedSubpaths();
+    project = m.projectSubpaths(projectFolder);
+
+    fprintf('Project:\n')
+    for i = 1:length(project)
+        fprintf('\t%s ', project{i});
+
+        if m.subpathIsActive(fullfile(projectFolder,project{i}), split(path, pathsep))
+            fprintf('(active)');
+        else
+            fprintf('(inactive)');
+        end
+
+        fprintf('\n')
+    end
+    fprintf('\n')
 
     fprintf('Loaded subpaths:\n')
-    for i = 1:length(subpaths);
-        fprintf('\t%s\n', subpaths{i});
+    for i = 1:length(loaded);
+        fprintf('\t%s\n', loaded{i});
     end
 end