a bit better arg handling...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-12-13 04:12:12 +03:00
parent aaecdfa1e3
commit f7d345b4ea
5 changed files with 39 additions and 19 deletions

View File

@ -23,6 +23,13 @@ var VERSION = require('./version').version
var app = electron.app var app = electron.app
var BrowserWindow = electron.BrowserWindow var BrowserWindow = electron.BrowserWindow
//
global.ELECTRON_PACKAGED = app.isPackaged
// used to let e.js know that the CLI wants to start the GUI..
global.START_GUI = false
/*********************************************************************/ /*********************************************************************/
@ -154,14 +161,10 @@ app.on('window-all-closed', function(){
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// start things up... // start things up...
global.START_GUI = false ;(ELECTRON_PACKAGED ?
process.argv.length > 1
var argv1 = process.argv[1] : process.argv.length > 2) ?
&& path.resolve(process.cwd(), process.argv[1]) // got some arguments -- delegate to ig.js...
;(process.argv.length > 2
|| (argv1 && argv1 != require.main.filename)) ?
// got some arguments -- trigger ig.js...
(require('./ig') (require('./ig')
&& global.START_GUI && global.START_GUI
&& start()) && start())

View File

@ -117,6 +117,7 @@ var CLIActions = actions.Actions({
var bar = state.bar = var bar = state.bar =
state.bar || container.create(0, 0, {text: text.padEnd(l)}) state.bar || container.create(0, 0, {text: text.padEnd(l)})
// XXX for some reason this does not work under electron...
bar.setTotal(Math.max(max, value)) bar.setTotal(Math.max(max, value))
bar.update(value) bar.update(value)
}], }],
@ -178,7 +179,10 @@ var CLIActions = actions.Actions({
// Startup commands... // Startup commands...
// //
startREPL: ['- System/Start CLI interpreter', startREPL: ['- System/Start CLI interpreter',
{cli: '@repl'}, {cli: {
name: '@repl',
interactive: true,
}},
function(){ function(){
var that = this var that = this
var repl = nodeRequire('repl') var repl = nodeRequire('repl')
@ -214,6 +218,7 @@ var CLIActions = actions.Actions({
// 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??? // XXX should we require electron or npx electron???
// XXX add --dev-tools flag...
startGUI: ['- System/Start viewer GUI', startGUI: ['- System/Start viewer GUI',
core.doc` core.doc`
@ -469,12 +474,14 @@ module.CLI = core.ImageGridFeatures.Feature({
function(){ function(){
var that = this var that = this
//var pkg = require('package.json')
var pkg = nodeRequire('./package.json') var pkg = nodeRequire('./package.json')
var wait_for = [] var wait_for = []
// XXX
var interactive = false
argv.Parser({ argv.Parser({
context: this, context: this,
script: nodeRequire.main.filename,
// XXX argv.js is not picking these up because // XXX argv.js is not picking these up because
// of the require(..) mixup... // of the require(..) mixup...
@ -511,6 +518,11 @@ module.CLI = core.ImageGridFeatures.Feature({
action action
: (cmd.key || cmd.name) : (cmd.key || cmd.name)
// skip interactive commands in non-interactive
// contexts...
if(!interactive && cmd.interactive){
return res }
res[name] = cmd instanceof argv.Parser ? res[name] = cmd instanceof argv.Parser ?
// parser... // parser...
cmd cmd

View File

@ -12,14 +12,12 @@ require('v8-compile-cache')
// NOTE: this fixes several issues with lib/util conflicting with stuff... // NOTE: this fixes several issues with lib/util conflicting with stuff...
require('repl') require('repl')
// setup module loaders... // setup module loaders...
require = require('./cfg/requirejs')(require).requirejs require = require('./cfg/requirejs')(require).requirejs
require.main = {filename: (nodeRequire.main || {}).filename} require.main = {filename: (nodeRequire.main || {}).filename}
/*********************************************************************/
var core = require('features/core') var core = require('features/core')
// XXX for some reason if this is not loaded here things break in CLI... // XXX for some reason if this is not loaded here things break in CLI...
// ...setting priority does not help... // ...setting priority does not help...
@ -28,7 +26,7 @@ var meta = require('features/meta')
//--------------------------------------------------------------------- /*********************************************************************/
// NOTE: this is here to simplify importing... // NOTE: this is here to simplify importing...
var ImageGridFeatures = var ImageGridFeatures =

View File

@ -1127,9 +1127,9 @@
} }
}, },
"ig-argv": { "ig-argv": {
"version": "2.16.2", "version": "2.16.3",
"resolved": "https://registry.npmjs.org/ig-argv/-/ig-argv-2.16.2.tgz", "resolved": "https://registry.npmjs.org/ig-argv/-/ig-argv-2.16.3.tgz",
"integrity": "sha512-bSOslxGN9XqJ+IVba/XC0h9p1r/z/25wmJ2ik2xCNlMU07WI/K2ensIFR93I0aVfLHxsV37G5CdlP8xmiRIcLg==", "integrity": "sha512-58WBfqqXNL6KV4CaSVmFAizqYd0ymGANe0F+d/Zue2JHXOpolB6jwY0glrzU09THZjipnNnB+LlUxYwcwDeTwA==",
"requires": { "requires": {
"ig-object": "^5.2.6" "ig-object": "^5.2.6"
} }
@ -1861,6 +1861,12 @@
"strip-json-comments": "~2.0.1" "strip-json-comments": "~2.0.1"
} }
}, },
"rcedit": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/rcedit/-/rcedit-2.3.0.tgz",
"integrity": "sha512-h1gNEl9Oai1oijwyJ1WYqYSXTStHnOcv1KYljg/8WM4NAg3H1KBK3azIaKkQ1WQl+d7PoJpcBMscPfLXVKgCLQ==",
"dev": true
},
"readable-stream": { "readable-stream": {
"version": "2.3.7", "version": "2.3.7",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz",

View File

@ -31,7 +31,7 @@
"glob": "^7.1.6", "glob": "^7.1.6",
"guarantee-events": "^1.0.0", "guarantee-events": "^1.0.0",
"ig-actions": "^3.24.22", "ig-actions": "^3.24.22",
"ig-argv": "^2.16.2", "ig-argv": "^2.16.3",
"ig-features": "^3.4.2", "ig-features": "^3.4.2",
"ig-object": "^5.4.12", "ig-object": "^5.4.12",
"ig-types": "^5.0.40", "ig-types": "^5.0.40",
@ -55,7 +55,8 @@
"devDependencies": { "devDependencies": {
"asar": "^3.0.1", "asar": "^3.0.1",
"electron-rebuild": "^1.11.0", "electron-rebuild": "^1.11.0",
"less": "^3.13.0" "less": "^3.13.0",
"rcedit": "*"
}, },
"bin": { "bin": {
"ig": "ig.js" "ig": "ig.js"