From afef0a36d45c3aa3b55a9263e295e7ba21513fc7 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 10 Dec 2020 06:05:02 +0300 Subject: [PATCH] working on CLI... Signed-off-by: Alex A. Naanou --- Viewer/features/cli.js | 135 ++++++++++++++++++++++++++++------ Viewer/features/filesystem.js | 6 +- Viewer/package-lock.json | 12 +-- Viewer/package.json | 4 +- 4 files changed, 125 insertions(+), 32 deletions(-) diff --git a/Viewer/features/cli.js b/Viewer/features/cli.js index d229c9b3..61d0dff4 100755 --- a/Viewer/features/cli.js +++ b/Viewer/features/cli.js @@ -56,11 +56,21 @@ if(typeof(process) != 'undefined'){ var CLIActions = actions.Actions({ + help: ['- System/Show action help', + function(...actions){ + Object.entries(this.getDoc(actions)) + .forEach(function([action, [s, l]]){ + console.log(l) + console.log('') + }) }], + + get cliActions(){ return this.actions .filter(function(action){ return this.getActionAttr(action, 'cli') }.bind(this)) }, + // XXX should this be here??? // ...move this to progress... // XXX we are missing some beats, is this because we do not let the @@ -199,6 +209,9 @@ var CLIActions = actions.Actions({ global.ImageGrid = this + global.help = function(...actions){ + global.ig.help(...actions) } + require('features/all') global.ImageGridFeatures = core.ImageGridFeatures @@ -247,11 +260,6 @@ var CLIActions = actions.Actions({ // Actions... // /*/ XXX - cliIndexInit: ['- System/Initialize and create index', - {cli: '@init'}, - function(){ - // XXX - }], // XXX this should be a nested parser... // args: // from=PATH @@ -289,19 +297,58 @@ var CLIActions = actions.Actions({ cliExportImages: ['- System/Export images', {cli: argv.Parser({ key: '@export', - arg: 'TO', - // XXX get the export options -- see export UI... + '-help-pattern': { + doc: 'Show image filename pattern info and exit', + priority: 89, + handler: function(){ + this.parent.context.help('formatImageName') + return argv.STOP } }, + '-version': undefined, + '-quiet': undefined, + '@from': { doc: 'Source path', - arg: 'FROM'}, + arg: 'FROM | from', + default: '.', }, '@to': { doc: 'Destination path', - arg: 'TO'}, + arg: 'TO | path', + required: true, + valueRequired: true, }, + // XXX these should get defaults from .config + '-include-virtual': { + doc: 'Include virtual blocks', + arg: 'BOOL | include-virtual', + type: 'bool', + default: true, }, + '-clean-target': { + doc: 'Cleanup target before export (backup)', + arg: 'BOOL | clean-target', + type: 'bool', + default: true, }, + // XXX add tip to get doc... + // .formatImageName(..) -- format docs... + '-image-name': { + doc: 'Image name pattern', + arg: 'PATTERN | preview-name-pattern', + default: '%(fav)l%n%(-%c)c', }, + '-mode': { + doc: 'Export mode', + arg: 'MODE | export-mode', + //default: 'copy best match', + default: 'resize', }, + // XXX add help on possible values... + '-image-size': { + doc: 'Output image size', + arg: 'SIZE | preview-size', + default: 1000, }, })}, function(){ - // XXX + console.log('EXPORT', ...arguments) + // XXX load from... + // XXX export to... }], // Utility... (EXPERIMENTAL) @@ -312,22 +359,53 @@ var CLIActions = actions.Actions({ // XXX should we support creating multiple indexes at the same time??? // XXX this is reletively generic, might be useful globally... // XXX should we use a clean index or do this in-place??? - makeIndex: ['- System/Make index', - {cli: { - name: '@make', - arg: 'PATH', - valueRequired: true, - }}, - function(path){ - var that = this + // XXX add ability to disable sort... + initIndex: ['- System/Make index', + core.doc` + Create index in current directory + .initIndex() + .initIndex('create') + -> promise + + Create index in path... + ,initIndex(path) + .initIndex('create', path) + -> promise + + + Update index in current directory + .initIndex('update') + -> promise + + Update index in path... + .initIndex('update', path) + -> promise + + `, + {cli: { + name: '@init', + arg: 'PATH', + //valueRequired: true, + }}, + function(path, options){ + // get mode... + if(path == 'create' || path == 'update'){ + var [mode, path, options] = arguments } + mode = mode || 'create' + // normalize path... path = util.normalizePath( - pathlib.resolve(process.cwd(), path)) + path ? + pathlib.resolve(process.cwd(), path) + : process.cwd()) + options = options || {} // XXX should we use a clean index or do this in-place??? //var index = this.constructor(..) var index = this - return index.loadImages(path) + return (mode == 'create' ? + index.loadImages(path) + : index.loadNewImages(path)) // save base index... .then(function(){ return index.saveIndex() }) @@ -342,6 +420,16 @@ var CLIActions = actions.Actions({ return index .sortImages() .saveIndex() }) }], + // XXX does not work yet... + updateIndex: ['- System/Update index', + {cli: { + name: '@update', + arg: 'PATH', + }}, + 'initIndex: "update" ...'], + cleanIndex: ['- System/', + {}, + function(path, options){}], }) @@ -380,6 +468,8 @@ module.CLI = core.ImageGridFeatures.Feature({ var pkg = nodeRequire('./package.json') argv.Parser({ + context: this, + // XXX argv.js is not picking these up because // of the require(..) mixup... author: pkg.author, @@ -418,9 +508,8 @@ module.CLI = core.ImageGridFeatures.Feature({ res[name] = cmd instanceof argv.Parser ? cmd // XXX need to call the action... - .then(function(){ - // XXX - }) + .then(function(unhandled, value, rest){ + that[action](value, this) }) : { doc: (that.getActionAttr(action, 'doc') || '') .split(/[\\\/]/g).pop(), diff --git a/Viewer/features/filesystem.js b/Viewer/features/filesystem.js index dc8a0a26..ebd6991d 100755 --- a/Viewer/features/filesystem.js +++ b/Viewer/features/filesystem.js @@ -1793,7 +1793,7 @@ var FileSystemWriterActions = actions.Actions({ // ...need a better name... // XXX add tags/keywords... // %(tag|...)k - if image is tagged with tag add text - formatImageName: ['- File/', + formatImageName: ['- File/Format image filename', core.doc` Filename patterns: @@ -2370,6 +2370,10 @@ var FileSystemWriterActions = actions.Actions({ .exportDirs(path) .exportDirs(settings) + settings format: + { + } + NOTE: see .formatImageName(..) for pattern syntax details. `, function(path, pattern, level_dir, size, include_virtual, clean_target_dir, logger){ diff --git a/Viewer/package-lock.json b/Viewer/package-lock.json index fb4e66b2..41f06f1f 100755 --- a/Viewer/package-lock.json +++ b/Viewer/package-lock.json @@ -1116,17 +1116,17 @@ "integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg==" }, "ig-actions": { - "version": "3.24.21", - "resolved": "https://registry.npmjs.org/ig-actions/-/ig-actions-3.24.21.tgz", - "integrity": "sha512-fPdi3BEKxKDVcYiO9+Utg3NCqCATQUXPU+wIbdAsA4+AT8zx1EPKZl+vLUn3V0VPKAh9O4bvlWxqNn4GNjC2fQ==", + "version": "3.24.22", + "resolved": "https://registry.npmjs.org/ig-actions/-/ig-actions-3.24.22.tgz", + "integrity": "sha512-aPTGlyAjecNS6eBzldLjIW0oDHHzglQYHk3eptU78OOiNkG0kTINmUAGaFjHswX0G9TftVQ4JGf+UxVQkqowAg==", "requires": { "ig-object": "^5.4.12" } }, "ig-argv": { - "version": "2.15.1", - "resolved": "https://registry.npmjs.org/ig-argv/-/ig-argv-2.15.1.tgz", - "integrity": "sha512-BJ0j6aoIkWVjXEVZ/A+U4FTn4DYqthZ5W0XwOQYkeuR85FXVZuAFo1Ugdz6DJp3J7WrdpVRXQpIFDRobB84eZw==", + "version": "2.15.6", + "resolved": "https://registry.npmjs.org/ig-argv/-/ig-argv-2.15.6.tgz", + "integrity": "sha512-jQeDbiafqDPKxymYdC81msNEUPEbj5Ocvh4QvucZNFJ0m2DTMxBI4tMgg7IAJJWxlMke1J0U/p7Nhs8m2RStcw==", "requires": { "ig-object": "^5.2.6" } diff --git a/Viewer/package.json b/Viewer/package.json index d34d539b..dfb7dcda 100755 --- a/Viewer/package.json +++ b/Viewer/package.json @@ -30,8 +30,8 @@ "generic-walk": "^1.4.0", "glob": "^7.1.6", "guarantee-events": "^1.0.0", - "ig-actions": "^3.24.21", - "ig-argv": "^2.15.1", + "ig-actions": "^3.24.22", + "ig-argv": "^2.15.6", "ig-features": "^3.4.2", "ig-object": "^5.4.12", "ig-types": "^5.0.40",