From 6b4dfe0320533432e7f1a11bdb710e9158e60bec Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Tue, 17 Jan 2023 19:26:46 +0300 Subject: [PATCH] more work on ig ls... Signed-off-by: Alex A. Naanou --- Viewer/features/cli.js | 31 +++++++++++++++++++++++++------ Viewer/imagegrid/file.js | 26 +++++++++++--------------- 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/Viewer/features/cli.js b/Viewer/features/cli.js index 148f4212..33e87d37 100755 --- a/Viewer/features/cli.js +++ b/Viewer/features/cli.js @@ -326,17 +326,36 @@ var CLIActions = actions.Actions({ doc: 'List nested/recursive indexes', type: 'bool', }, + + '-n': '-nested-only', + '-nested-only': { + doc: 'Ignore the top-level index and only list the indexes below', + type: 'bool', + }, + })}, function(path, options={}){ + var that = this + this.setupFeatures() file.listIndexes(path) .on('end', function(paths){ - paths = - (options.recursive ? - paths - : file.skipNested(paths)) - .sortAs(paths) + paths = paths + .map(function(p){ + return p + .split(that.config['index-dir']) + .shift() }) + // normalize path... + path.at(-1) != '/' + && (path += '/') + // handle --nested-only + options['nested-only'] + && paths.splice(paths.indexOf(path), 1) + paths = options.recursive ? + paths + : file.skipNested(paths) + .sortAs(paths) for(var p of paths){ - console.log(p.replace(/.ImageGrid$/, '')) } }) }], + console.log(p) } }) }], /* XXX startWorker: ['- System/Start as worker', diff --git a/Viewer/imagegrid/file.js b/Viewer/imagegrid/file.js index c192c2e4..0bc6f0c3 100755 --- a/Viewer/imagegrid/file.js +++ b/Viewer/imagegrid/file.js @@ -43,30 +43,26 @@ var INDEX_DIR = '.ImageGrid' var skipNested = module.skipNested = function(paths, index_dir, logger){ + index_dir = index_dir || INDEX_DIR logger = logger && logger.push('Skipping nested') paths = paths - .map(function(p){ return p.split(index_dir).shift() }) - .sort(function(a, b){ return a.length - b.length }) + .map(function(p){ + return p.split(index_dir).shift() }) + .sort(function(a, b){ + return a.length - b.length }) for(var i=0; i < paths.length; i++){ var p = paths[i] - - if(p == null){ - continue - } - + if(p instanceof Array){ + continue } for(var j=i+1; j < paths.length; j++){ + if(paths[j] instanceof Array){ + continue } var o = paths[j].split(p) - if(o[0] == '' && o.length > 1){ logger && logger.emit('skipping', paths[j]) - delete paths[j] - } - } - } - return paths - .filter(function(p){ return !!p }) -} + paths[j] = [] } } } + return paths.flat() } // Guarantee that the 'end' and 'match' handlers will always get called