jsir 2.1.6 → 2.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cmd/oaa.js +76 -25
- package/deps/util.js +11 -4
- package/package.json +1 -1
package/cmd/oaa.js
CHANGED
|
@@ -6,7 +6,8 @@ const {
|
|
|
6
6
|
arrayDataFile, infoStr, warnStr, errorStack,
|
|
7
7
|
getInfo, ei, pad, msgStr, getType,
|
|
8
8
|
errorTag, isArgsMatch, draftQuery, setConfig,
|
|
9
|
-
$log, $draft, getTextComments, getOr, importG, requireG
|
|
9
|
+
$log, $draft, getTextComments, getOr, importG, requireG,
|
|
10
|
+
clearConsole
|
|
10
11
|
} = $lib;
|
|
11
12
|
const _args = process.argv.slice(2).map(trim);
|
|
12
13
|
const evalCode = require('../deps/evalCode')
|
|
@@ -381,7 +382,9 @@ function _nextLine(callback, promptStr, hidden, resolve, end, isText) {
|
|
|
381
382
|
_haveWrapperInput = true;
|
|
382
383
|
closeRl()
|
|
383
384
|
inputStr = inputStr.replace(/\s+$/, '');
|
|
384
|
-
|
|
385
|
+
if (!isText && /^\d+$/.test(inputStr) && /^\s+/.test(textLine)) {
|
|
386
|
+
inputStr = "& " + inputStr;
|
|
387
|
+
}
|
|
385
388
|
let pro = (callback || wrapperInput)(inputStr);
|
|
386
389
|
resolve && resolve(inputStr);
|
|
387
390
|
try {
|
|
@@ -390,7 +393,11 @@ function _nextLine(callback, promptStr, hidden, resolve, end, isText) {
|
|
|
390
393
|
if ((callback || wrapperInput) === wrapperInput) {
|
|
391
394
|
if (!_noAppendNextLine) {
|
|
392
395
|
if (/^\s+$/.test(textLine)) {
|
|
393
|
-
|
|
396
|
+
if (textLine.length > 1) {
|
|
397
|
+
clearConsole(false)
|
|
398
|
+
} else {
|
|
399
|
+
clearConsole();
|
|
400
|
+
}
|
|
394
401
|
listCmd();
|
|
395
402
|
nextLine(null, defaultPromptStr(true))
|
|
396
403
|
} else {
|
|
@@ -505,6 +512,9 @@ function listCmd(tmpMap) {
|
|
|
505
512
|
warn("no items")
|
|
506
513
|
} else {
|
|
507
514
|
items.forEach(item => {
|
|
515
|
+
if (tmpList && item.key) {
|
|
516
|
+
item.key = ' - '
|
|
517
|
+
}
|
|
508
518
|
if (item.type) {
|
|
509
519
|
let pair = parseUniqueName(item.name);
|
|
510
520
|
if (item.type.startsWith('exe.')) {
|
|
@@ -539,11 +549,11 @@ async function _wrapperInput(str) {
|
|
|
539
549
|
}
|
|
540
550
|
if (/^&/.test(str)) {
|
|
541
551
|
let cmdStr = trim(str.substr(1));
|
|
542
|
-
if (/^\d+$/.test(cmdStr)
|
|
552
|
+
if (/^\d+$/.test(cmdStr)) {
|
|
543
553
|
if (_cmdMap[cmdStr]) {
|
|
544
554
|
ei('vi', [getFullPath(_cmdMap[cmdStr])])
|
|
545
555
|
} else {
|
|
546
|
-
|
|
556
|
+
ei('vi', ['-n'])
|
|
547
557
|
}
|
|
548
558
|
} else if (cmdStr) {
|
|
549
559
|
ei(cmdStr.split(/\s+/)[0],
|
|
@@ -1038,21 +1048,31 @@ const keywordDef = {
|
|
|
1038
1048
|
warn('invalid args')
|
|
1039
1049
|
return
|
|
1040
1050
|
}
|
|
1041
|
-
let
|
|
1051
|
+
let keyword = args[0]
|
|
1052
|
+
let justList = false;
|
|
1053
|
+
if (keyword.endsWith('.')) {
|
|
1054
|
+
let _tmp = trim(keyword.substring(0, keyword.length - 1));
|
|
1055
|
+
if (_tmp) {
|
|
1056
|
+
justList = true;
|
|
1057
|
+
keyword = _tmp;
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
let pair = parseUniqueName(keyword)
|
|
1042
1061
|
let cmds;
|
|
1043
1062
|
if (/^0x[a-z\d]{8}$/.test(pair[1]) || pair[1].indexOf(",") !== -1) {
|
|
1044
|
-
cmds = getQuickRunCmds(
|
|
1063
|
+
cmds = getQuickRunCmds(keyword, keyword)
|
|
1045
1064
|
} else {
|
|
1046
|
-
cmds = getQuickRunCmds(
|
|
1065
|
+
cmds = getQuickRunCmds(keyword, '^e ' + toJsirFileName(pair[1]) + '$')
|
|
1047
1066
|
if (cmds.length === 0) {
|
|
1048
|
-
cmds = getQuickRunCmds(
|
|
1067
|
+
cmds = getQuickRunCmds(keyword, keyword)
|
|
1049
1068
|
}
|
|
1050
1069
|
}
|
|
1051
1070
|
if (cmds.length === 1) {
|
|
1052
|
-
if (
|
|
1071
|
+
if (justList) {
|
|
1053
1072
|
listCmd(arrayToCmdMap(cmds))
|
|
1073
|
+
} else {
|
|
1074
|
+
await runCmd(args.slice(1).join(' '), cmds[0])
|
|
1054
1075
|
}
|
|
1055
|
-
await runCmd(args.slice(1).join(' '), cmds[0])
|
|
1056
1076
|
} else {
|
|
1057
1077
|
warn(cmds.length > 1 ? "multiple match" : "no match")
|
|
1058
1078
|
}
|
|
@@ -1367,18 +1387,15 @@ function parseUniqueName(uniqueName) {
|
|
|
1367
1387
|
function getArgComments(argDef) {
|
|
1368
1388
|
let comments = []
|
|
1369
1389
|
let keys = Object.keys(argDef)
|
|
1390
|
+
let shortMap = {}
|
|
1391
|
+
let tempShortMap = getShortDefMap(keys)
|
|
1392
|
+
for (let key of Object.keys(tempShortMap)) {
|
|
1393
|
+
shortMap[tempShortMap[key].replace(/^:/, '')] = key;
|
|
1394
|
+
}
|
|
1370
1395
|
if (keys.length > 0) {
|
|
1371
|
-
let aLine = []
|
|
1372
1396
|
for (let k of keys) {
|
|
1373
|
-
let item = warnStr(k) + (argDef[k] ? ` <${argDef[k]}>`:'')
|
|
1374
|
-
|
|
1375
|
-
comments.push(aLine.join(", ") + ", ")
|
|
1376
|
-
aLine = []
|
|
1377
|
-
}
|
|
1378
|
-
aLine.push(item)
|
|
1379
|
-
}
|
|
1380
|
-
if (aLine.length > 0) {
|
|
1381
|
-
comments.push(aLine.join(", "))
|
|
1397
|
+
let item = warnStr(k) + (shortMap[k] ? ` ${warnStr(shortMap[k])}`:'') + (argDef[k] ? ` <${argDef[k]}>`:'')
|
|
1398
|
+
comments.push(item)
|
|
1382
1399
|
}
|
|
1383
1400
|
comments[0] = '$args: ' + comments[0]
|
|
1384
1401
|
if (comments.length > 1) {
|
|
@@ -1390,6 +1407,39 @@ function getArgComments(argDef) {
|
|
|
1390
1407
|
return comments
|
|
1391
1408
|
}
|
|
1392
1409
|
|
|
1410
|
+
function getShortStr(str) {
|
|
1411
|
+
let result = []
|
|
1412
|
+
for (let i = 0; i < str.length; i++) {
|
|
1413
|
+
if (i === 0) {
|
|
1414
|
+
result.push(str[i].toLowerCase())
|
|
1415
|
+
}
|
|
1416
|
+
if (/[A-Z]/.test(str[i])) {
|
|
1417
|
+
result.push(str[i].toLowerCase())
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
return result.join('');
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
function getShortDefMap(argDefKeys) {
|
|
1424
|
+
const result = {};
|
|
1425
|
+
for (let str of argDefKeys) {
|
|
1426
|
+
let originStr = ":" + str;
|
|
1427
|
+
str = str.replace(/^:/, '')
|
|
1428
|
+
str = str.replace(/^_/, '')
|
|
1429
|
+
let shortStr = getShortStr(str);
|
|
1430
|
+
let key = '-' + shortStr;
|
|
1431
|
+
let val = result[key]
|
|
1432
|
+
let i = 1;
|
|
1433
|
+
while (val) {
|
|
1434
|
+
key = '-' + shortStr + i;
|
|
1435
|
+
val = result[key];
|
|
1436
|
+
i ++;
|
|
1437
|
+
}
|
|
1438
|
+
result[key] = originStr;
|
|
1439
|
+
}
|
|
1440
|
+
return result;
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1393
1443
|
async function runCmd(str = '', uniqueName = '', text = '') {
|
|
1394
1444
|
let path = getFullPath(uniqueName);
|
|
1395
1445
|
if (uniqueName || text) {
|
|
@@ -1418,8 +1468,9 @@ async function runCmd(str = '', uniqueName = '', text = '') {
|
|
|
1418
1468
|
return;
|
|
1419
1469
|
}
|
|
1420
1470
|
|
|
1421
|
-
let oriArgs = enrichArgs(str, text)
|
|
1422
1471
|
let argDef = getArgDef(text)
|
|
1472
|
+
let shortDefMap = getShortDefMap(Object.keys(argDef))
|
|
1473
|
+
let oriArgs = enrichArgs(str).map(i => shortDefMap[i] ? shortDefMap[i]:i)
|
|
1423
1474
|
if (argDef['[ParseError]']) {
|
|
1424
1475
|
throw `argDef [ParseError] ${argDef['[ParseError]']}`
|
|
1425
1476
|
}
|
|
@@ -1430,7 +1481,7 @@ async function runCmd(str = '', uniqueName = '', text = '') {
|
|
|
1430
1481
|
let arg = oriArgs[i]
|
|
1431
1482
|
let needTrans
|
|
1432
1483
|
let pair
|
|
1433
|
-
if (arg.startsWith(":") || arg.startsWith("_")) {
|
|
1484
|
+
if (arg.startsWith(":") || arg.startsWith("_") && !arg.endsWith(' ')) {
|
|
1434
1485
|
arg = arg.replace(/^:/, '')
|
|
1435
1486
|
if (oriArgs[i+1] && !(oriArgs[i+1].startsWith(":") || oriArgs[i+1].startsWith("_"))) {
|
|
1436
1487
|
pair = [arg, oriArgs[i+1]]
|
|
@@ -1532,8 +1583,8 @@ function getArgDef(text) {
|
|
|
1532
1583
|
argDef = (exeStr ? evalVal(exeStr) : {}) || {}
|
|
1533
1584
|
let array = []
|
|
1534
1585
|
for (let key of Object.keys(argDef)) {
|
|
1535
|
-
if (array.hasOwnProperty(key)) {
|
|
1536
|
-
throw `invalid argName ${key}`
|
|
1586
|
+
if (/\s/.test(key) || array.hasOwnProperty(key)) {
|
|
1587
|
+
throw `invalid argName ${warnStr(key)}`
|
|
1537
1588
|
}
|
|
1538
1589
|
}
|
|
1539
1590
|
} catch (e) {
|
package/deps/util.js
CHANGED
|
@@ -13,7 +13,7 @@ const globalDirectories = require('global-dirs');
|
|
|
13
13
|
const emptyFn = ()=>{}
|
|
14
14
|
const dayJs = require('dayjs')
|
|
15
15
|
const table = require('console.table')
|
|
16
|
-
const {log: _log} = console;
|
|
16
|
+
const {log: _log, clear: _clear} = console;
|
|
17
17
|
const _fs = require("fs");
|
|
18
18
|
if (module.paths.indexOf(globalDirectories.npm.packages) === -1) {
|
|
19
19
|
module.paths.push(globalDirectories.npm.packages)
|
|
@@ -213,9 +213,16 @@ async function timeLimit(proms, mills) {
|
|
|
213
213
|
return result
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
-
function clearConsole() {
|
|
217
|
-
|
|
218
|
-
|
|
216
|
+
function clearConsole(clean = true) {
|
|
217
|
+
if (clean) {
|
|
218
|
+
// \033[0f 清除从光标位置到屏幕末尾的内容,并把光标移动到屏幕的左上角。
|
|
219
|
+
// process.stdout.write('\033[0f');
|
|
220
|
+
_clear();
|
|
221
|
+
} else {
|
|
222
|
+
// \033[2J:清空屏幕。
|
|
223
|
+
// \033[H:将光标定位到屏幕左上角。
|
|
224
|
+
process.stdout.write('\033[2J\033[H');
|
|
225
|
+
}
|
|
219
226
|
}
|
|
220
227
|
|
|
221
228
|
function appendLog(fileName, text) {
|