cleanup and some polish...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2023-01-18 01:04:42 +03:00
parent 3ef431eae4
commit e96aff481e
2 changed files with 123 additions and 89 deletions

View File

@ -48,13 +48,11 @@ var CLIActions = actions.Actions({
console.log('') console.log('')
}) }], }) }],
get cliActions(){ get cliActions(){
return this.actions return this.actions
.filter(function(action){ .filter(function(action){
return this.getActionAttr(action, 'cli') }.bind(this)) }, return this.getActionAttr(action, 'cli') }.bind(this)) },
// XXX should this be here??? // XXX should this be here???
// ...move this to progress... // ...move this to progress...
// XXX we are missing some beats, is this because we do not let the // XXX we are missing some beats, is this because we do not let the
@ -178,7 +176,6 @@ var CLIActions = actions.Actions({
this.showProgress(['Error'].concat(msg), '+0', '+'+l) } this.showProgress(['Error'].concat(msg), '+0', '+'+l) }
}], }],
// XXX SETUP revise default... // XXX SETUP revise default...
setupFeatures: ['- System/', setupFeatures: ['- System/',
function(...tags){ function(...tags){
@ -194,18 +191,22 @@ var CLIActions = actions.Actions({
// Startup commands... // Startup commands...
// //
startREPL: ['- System/Start CLI interpreter', cliStartREPL: ['- System/CLI/start CLI interpreter',
{cli: { {cli: {
name: '@repl', name: '@repl',
arg: 'PATH'
//interactive: true, //interactive: true,
}}, }},
function(){ function(path, options){
var that = this var that = this
var repl = nodeRequire('repl') var repl = nodeRequire('repl')
// XXX SETUP // XXX SETUP
this.setupFeatures() this.setupFeatures()
if(path){
this.loadIndex(path) }
this.__keep_running = true this.__keep_running = true
// setup the global ns... // setup the global ns...
@ -238,14 +239,38 @@ var CLIActions = actions.Actions({
that.stop() }) }], that.stop() }) }],
// XXX move this to a feature that requires electron... // XXX move this to a feature that requires electron...
// ...and move electron to an optional dependency... // ...and move electron to an optional dependency...
// XXX should we require electron or npx electron??? cliStartGUI: ['- System/CLI/start viewer GUI',
// XXX add --dev-tools flag...
startGUI: ['- System/Start viewer GUI',
core.doc` core.doc`
NOTE: this will not wait for the viewer to exit.`, NOTE: this will not wait for the viewer to exit.`,
{cli: '@gui'}, {cli: argv && argv.Parser({
function(){ key: '@gui',
arg: 'PATH',
doc: 'start viewer GUI',
'-version': undefined,
'-quiet': undefined,
'-devtools': {
doc: 'show DevTools',
type: 'bool',
},
'-show': {
doc: 'force show interface',
type: 'bool',
},
})},
function(path, options={}){
var env = { ...process.env }
path
&& (env.IMAGEGRID_PATH =
util.normalizePath(
pathlib.resolve(process.cwd(), path)))
options.devtools
&& (env.IMAGEGRID_DEBUG = true)
options.show
&& (env.IMAGEGRID_FORCE_SHOW = true)
// already in electron... // already in electron...
if(process.versions.electron){ if(process.versions.electron){
// XXX this feels hackish... // XXX this feels hackish...
@ -258,12 +283,16 @@ var CLIActions = actions.Actions({
[ pathlib.join( [ pathlib.join(
pathlib.dirname(nodeRequire.main.filename), pathlib.dirname(nodeRequire.main.filename),
'e.js') ], 'e.js') ],
{ detached: true, }) } }], {
detached: true,
env,
}) } }],
// Introspection... // Introspection...
// //
// XXX revise naming...
// XXX handle errors... // XXX handle errors...
cliInfo: ['- System/Show information about index in PATH', cliInfo: ['- System/CLI/show information about index in PATH',
{cli: { {cli: {
name: '@info', name: '@info',
arg: 'PATH', arg: 'PATH',
@ -300,24 +329,24 @@ var CLIActions = actions.Actions({
Modified date: ${ modified }`) }, Modified date: ${ modified }`) },
function(err){ function(err){
console.error('Can\'t find or load index at:', path) }) }], console.error('Can\'t find or load index at:', path) }) }],
// XXX handle errors... cliListIndexes: ['- System/CLI/list indexes in PATH',
cliListIndexes: ['- System/List indexes in PATH',
{cli: argv && argv.Parser({ {cli: argv && argv.Parser({
key: '@ls', key: '@ls',
arg: 'PATH', arg: 'PATH',
doc: 'list indexes in PATH',
'-version': undefined, '-version': undefined,
'-quiet': undefined, '-quiet': undefined,
'-r': '-recursive', '-r': '-recursive',
'-recursive': { '-recursive': {
doc: 'List nested/recursive indexes', doc: 'list nested/recursive indexes',
type: 'bool', type: 'bool',
}, },
'-n': '-nested-only', '-n': '-nested-only',
'-nested-only': { '-nested-only': {
doc: 'Ignore the top-level index and only list the indexes below', doc: 'ignore the top-level index and only list the indexes below',
type: 'bool', type: 'bool',
}, },
@ -348,12 +377,10 @@ var CLIActions = actions.Actions({
.sortAs(paths) .sortAs(paths)
for(var p of paths){ for(var p of paths){
console.log(p) } }) }], console.log(p) } }) }],
// XXX revise naming... cliListCollections: ['- System/CLI/list collections in index',
// XXX how do we handle errors???
cliListCollections: ['- System/List collections in index',
{cli: argv && argv.Parser({ {cli: argv && argv.Parser({
key: '@collections', key: '@collections',
doc: 'List collection in index at PATH', doc: 'list collection in index at PATH',
arg: 'PATH', arg: 'PATH',
'-version': undefined, '-version': undefined,
@ -387,59 +414,16 @@ var CLIActions = actions.Actions({
// XXX how do we handle rejection??? // XXX how do we handle rejection???
console.error('Can\'t find or load index at:', path) }) }], console.error('Can\'t find or load index at:', path) }) }],
/* XXX
startWorker: ['- System/Start as worker',
{cli: '-worker'},
function(){
// XXX
}],
// Actions...
//
// XXX
// XXX this should be a nested parser...
// args:
// from=PATH
// to=PATH
// ...
cliExportIindex: ['- System/Clone index',
{cli: {
name: '@clone',
arg: 'PATH',
valueRequired: true,
}},
function(){
// XXX
}],
cliPullChanges: ['- System/Pull changes',
{cli: {
name: '@pull',
arg: 'PATH',
valueRequired: true,
}},
function(){
// XXX
}],
cliPushChanges: ['- System/Push changes',
{cli: {
name: '@push',
arg: 'PATH',
valueRequired: true,
}},
function(){
// XXX
}],
//*/
// XXX report that can't find an index... // XXX report that can't find an index...
// XXX move options to generic object for re-use... // XXX move options to generic object for re-use...
// XXX how do we handle errors??? // XXX how do we handle errors???
cliExportImages: ['- System/Export images', cliExportImages: ['- System/CLI/export images',
{cli: argv && argv.Parser({ {cli: argv && argv.Parser({
key: '@export', key: '@export',
doc: 'export images',
// help... // help...
'-help-pattern': { '-help-pattern': {
doc: 'Show image filename pattern info and exit', doc: 'show image filename pattern info and exit',
priority: 89, priority: 89,
handler: function(){ handler: function(){
this.parent.context this.parent.context
@ -452,55 +436,55 @@ var CLIActions = actions.Actions({
'-quiet': undefined, '-quiet': undefined,
// commands... // commands...
'@from': { '@from': {
doc: 'Source path', doc: 'source path',
arg: 'PATH | from', arg: 'PATH | from',
default: '.', default: '.',
valueRequired: true, }, valueRequired: true, },
// XXX // XXX
'@collection': { '@collection': {
doc: 'Source collection (name/gid)', doc: 'source collection (name/gid)',
arg: 'COLLECTION | collection', arg: 'COLLECTION | collection',
//default: 'ALL', //default: 'ALL',
valueRequired: false, }, valueRequired: false, },
//*/ //*/
'@to': { '@to': {
doc: 'Destination path', doc: 'destination path',
arg: 'PATH | path', arg: 'PATH | path',
required: true, required: true,
valueRequired: true, }, valueRequired: true, },
// bool options... // bool options...
// XXX these should get defaults from .config // XXX these should get defaults from .config
'-include-virtual': { '-include-virtual': {
doc: 'Include virtual blocks', doc: 'include virtual blocks',
arg: '| include-virtual', arg: '| include-virtual',
type: 'bool', type: 'bool',
//value: true, //value: true,
default: true, }, default: true, },
'-clean-target': { '-clean-target': {
doc: 'Cleanup target before export (backup)', doc: 'cleanup target before export (backup)',
arg: '| clean-target', arg: '| clean-target',
type: 'bool', type: 'bool',
//value: true, //value: true,
default: true, }, default: true, },
'-no-*': { '-no-*': {
doc: 'Negate boolean option value', doc: 'negate boolean option value',
handler: function(rest, key, value, ...args){ handler: function(rest, key, value, ...args){
rest.unshift(key.replace(/^-?-no/, '') +'=false') } }, rest.unshift(key.replace(/^-?-no/, '') +'=false') } },
// options... // options...
'-image-name': { '-image-name': {
doc: 'Image name pattern', doc: 'image name pattern',
arg: 'PATTERN | preview-name-pattern', arg: 'PATTERN | preview-name-pattern',
default: '%(fav)l%n%(-%c)c', default: '%(fav)l%n%(-%c)c',
valueRequired: true, }, valueRequired: true, },
'-mode': { '-mode': {
// XXX get doc values from system... // XXX get doc values from system...
doc: 'Export mode, can be "resize" or "copy best match"', doc: 'export mode, can be "resize" or "copy best match"',
arg: 'MODE | export-mode', arg: 'MODE | export-mode',
//default: 'copy best match', //default: 'copy best match',
default: 'resize', default: 'resize',
valueRequired: true, }, valueRequired: true, },
'-image-size': { '-image-size': {
doc: 'Output image size', doc: 'output image size',
arg: 'SIZE | preview-size', arg: 'SIZE | preview-size',
default: 1000, default: 1000,
valueRequired: true, }, valueRequired: true, },
@ -555,26 +539,26 @@ var CLIActions = actions.Actions({
// XXX this is reletively generic, might be useful globally... // XXX this is reletively generic, might be useful globally...
// XXX should we use a clean index or do this in-place??? // XXX should we use a clean index or do this in-place???
// XXX add ability to disable sort... // XXX add ability to disable sort...
initIndex: ['- System/Make index', cliInitIndex: ['- System/CLI/make index',
core.doc` core.doc`
Create index in current directory Create index in current directory
.initIndex() .cliInitIndex()
.initIndex('create') .cliInitIndex('create')
-> promise -> promise
Create index in path... Create index in path...
,initIndex(path) ,cliInitIndex(path)
.initIndex('create', path) .cliInitIndex('create', path)
-> promise -> promise
Update index in current directory Update index in current directory
.initIndex('update') .cliInitIndex('update')
-> promise -> promise
Update index in path... Update index in path...
.initIndex('update', path) .cliInitIndex('update', path)
-> promise -> promise
`, `,
@ -620,7 +604,7 @@ var CLIActions = actions.Actions({
.saveIndex() }) }], .saveIndex() }) }],
// XXX this is still wrong... // XXX this is still wrong...
_makeIndex: ['- System/', _cliMakeIndex: ['- System/',
`chain: [ `chain: [
"loadImages: $1", "loadImages: $1",
"saveIndex", "saveIndex",
@ -629,15 +613,60 @@ var CLIActions = actions.Actions({
"saveIndex", ]`], "saveIndex", ]`],
// XXX does not work yet... // XXX does not work yet...
updateIndex: ['- System/Update index', cliUpdateIndex: ['- System/CLI/update index',
{cli: { {cli: {
name: '@update', name: '@update',
arg: 'PATH', arg: 'PATH',
}}, }},
'initIndex: "update" ...'], 'cliInitIndex: "update" ...'],
cleanIndex: ['- System/', cliCleanIndex: ['- System/',
{}, {},
function(path, options){}], function(path, options){}],
/* XXX
cliStartServer: ['- System/CLI/start as server',
{cli: '-server'},
function(){
// XXX
}],
// Actions...
//
// XXX
// XXX this should be a nested parser...
// args:
// from=PATH
// to=PATH
// ...
cliExportIindex: ['- System/CLI/clone index',
{cli: {
name: '@clone',
arg: 'PATH',
valueRequired: true,
}},
function(){
// XXX
}],
cliPullChanges: ['- System/CLI/pull changes',
{cli: {
name: '@pull',
arg: 'PATH',
valueRequired: true,
}},
function(){
// XXX
}],
cliPushChanges: ['- System/CLI/push changes',
{cli: {
name: '@push',
arg: 'PATH',
valueRequired: true,
}},
function(){
// XXX
}],
//*/
}) })
@ -692,13 +721,13 @@ module.CLI = core.ImageGridFeatures.Feature({
license: pkg.license, license: pkg.license,
'-verbose': { '-verbose': {
doc: 'Enable verbose (very) output', doc: 'enable (very) verbose output',
handler: function(){ handler: function(){
that.logger that.logger
&& (that.logger.quiet = false) } }, && (that.logger.quiet = false) } },
// XXX merge this with -quiet... // XXX merge this with -quiet...
'-no-progress': { '-no-progress': {
doc: 'Disable progress bar display', doc: 'disable progress bar display',
handler: function(){ handler: function(){
that.__progress = false } }, that.__progress = false } },

View File

@ -457,7 +457,12 @@ module.URLHistoryLocalStorage = core.ImageGridFeatures.Feature({
// NOTE: loading is done by the .url_history prop... // NOTE: loading is done by the .url_history prop...
handlers: [ handlers: [
['ready', ['ready',
function(){ this.loadLastSavedBasePath() }], function(){
;(typeof(process) != 'undefined'
&& process.env.IMAGEGRID_PATH
&& this.loadIndex) ?
this.loadIndex(process.env.IMAGEGRID_PATH)
: this.loadLastSavedBasePath() }],
['stop.pre', ['stop.pre',
function(){ this.storeURLHistory() }], function(){ this.storeURLHistory() }],