changeset 5:6c46515ee860

Add function for checking if the currently loaded paths are correct
author Jonatan Werpers <jonatan@werpers.com>
date Mon, 10 Sep 2018 16:35:17 +0200
parents 38c29c9ba07f
children 19c4af287596
files +mpm/check.m
diffstat 1 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/+mpm/check.m	Mon Sep 10 16:35:17 2018 +0200
@@ -0,0 +1,28 @@
+% Check if the current proejct settings are correct
+% The right version is in the path
+% The right version is at the top of the path
+%
+% Useful to put at the top of some scripts
+function check()
+    folders = split(path(), pathsep);
+
+    sp = mpm.subpaths();
+    for i = 1:length(sp)
+        if ~isAtTop(sp{i}, fullfile(pwd, sp{i}), folders)
+            error('Subpaths are not correctly set. Try running mpm.set()');
+        end
+    end
+end
+
+function b = isAtTop(subpath, fullsubpath, paths)
+    for i = 1:length(paths)
+        if ~endsWith(paths{i}, subpath)
+            continue
+        end
+
+        b = strcmp(fullsubpath, paths{i});
+        return
+    end
+
+    b = false;
+end