jsir 2.1.7 → 2.1.8
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 +41 -17
- package/package.json +1 -1
package/cmd/oaa.js
CHANGED
|
@@ -556,8 +556,7 @@ async function _wrapperInput(str) {
|
|
|
556
556
|
ei('vi', ['-n'])
|
|
557
557
|
}
|
|
558
558
|
} else if (cmdStr) {
|
|
559
|
-
ei(cmdStr.split(/\s+/)[0],
|
|
560
|
-
enrichArgs(trim(cmdStr.replace(/^\S+/, ''))).map(trim));
|
|
559
|
+
ei(cmdStr.split(/\s+/)[0], enrichArgs(trim(cmdStr.replace(/^\S+/, ''))).map(trim));
|
|
561
560
|
} else {
|
|
562
561
|
ei('vi', ['-n'])
|
|
563
562
|
}
|
|
@@ -1071,7 +1070,7 @@ const keywordDef = {
|
|
|
1071
1070
|
if (justList) {
|
|
1072
1071
|
listCmd(arrayToCmdMap(cmds))
|
|
1073
1072
|
} else {
|
|
1074
|
-
await
|
|
1073
|
+
await runScript(cmds[0], args.slice(1))
|
|
1075
1074
|
}
|
|
1076
1075
|
} else {
|
|
1077
1076
|
warn(cmds.length > 1 ? "multiple match" : "no match")
|
|
@@ -1139,7 +1138,7 @@ async function dealKeyword(items) {
|
|
|
1139
1138
|
continue
|
|
1140
1139
|
}
|
|
1141
1140
|
if (keyword) {
|
|
1142
|
-
args.push(
|
|
1141
|
+
args.push(item)
|
|
1143
1142
|
}
|
|
1144
1143
|
}
|
|
1145
1144
|
if (keyword) {
|
|
@@ -1158,7 +1157,11 @@ async function _dealKeyword(keyword, args) {
|
|
|
1158
1157
|
let shortKey = keyword === key ? item.short : keyword;
|
|
1159
1158
|
if (item.short === shortKey) {
|
|
1160
1159
|
unMatched = false;
|
|
1161
|
-
|
|
1160
|
+
if (item === keywordDef.run) {
|
|
1161
|
+
await item.exeFn(args);
|
|
1162
|
+
} else {
|
|
1163
|
+
await item.exeFn(args.map(trim));
|
|
1164
|
+
}
|
|
1162
1165
|
break;
|
|
1163
1166
|
}
|
|
1164
1167
|
}
|
|
@@ -1243,7 +1246,7 @@ function getComments(i, cmdName, text, cols = [], col) {
|
|
|
1243
1246
|
text = trim(text)
|
|
1244
1247
|
docLines.push(...getTextComments(text))
|
|
1245
1248
|
let argDef = getArgDef(text)
|
|
1246
|
-
let comments = getArgComments(argDef)
|
|
1249
|
+
let comments = getArgComments(argDef, true)
|
|
1247
1250
|
if (comments) {
|
|
1248
1251
|
docLines.push(...comments)
|
|
1249
1252
|
}
|
|
@@ -1384,13 +1387,15 @@ function parseUniqueName(uniqueName) {
|
|
|
1384
1387
|
return [pair[len - 2], pair[len - 1]]
|
|
1385
1388
|
}
|
|
1386
1389
|
|
|
1387
|
-
function getArgComments(argDef) {
|
|
1390
|
+
function getArgComments(argDef, showShort = false) {
|
|
1388
1391
|
let comments = []
|
|
1389
1392
|
let keys = Object.keys(argDef)
|
|
1390
1393
|
let shortMap = {}
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
+
if (showShort) {
|
|
1395
|
+
let tempShortMap = getShortDefMap(keys)
|
|
1396
|
+
for (let key of Object.keys(tempShortMap)) {
|
|
1397
|
+
shortMap[tempShortMap[key].replace(/^:/, '')] = key;
|
|
1398
|
+
}
|
|
1394
1399
|
}
|
|
1395
1400
|
if (keys.length > 0) {
|
|
1396
1401
|
for (let k of keys) {
|
|
@@ -1425,6 +1430,9 @@ function getShortDefMap(argDefKeys) {
|
|
|
1425
1430
|
for (let str of argDefKeys) {
|
|
1426
1431
|
let originStr = ":" + str;
|
|
1427
1432
|
str = str.replace(/^:/, '')
|
|
1433
|
+
if (!str.startsWith("_")) {
|
|
1434
|
+
continue;
|
|
1435
|
+
}
|
|
1428
1436
|
str = str.replace(/^_/, '')
|
|
1429
1437
|
let shortStr = getShortStr(str);
|
|
1430
1438
|
let key = '-' + shortStr;
|
|
@@ -1469,11 +1477,27 @@ async function runCmd(str = '', uniqueName = '', text = '') {
|
|
|
1469
1477
|
}
|
|
1470
1478
|
|
|
1471
1479
|
let argDef = getArgDef(text)
|
|
1472
|
-
let shortDefMap = getShortDefMap(Object.keys(argDef))
|
|
1473
|
-
let oriArgs = enrichArgs(str).map(i => shortDefMap[i] ? shortDefMap[i]:i)
|
|
1474
1480
|
if (argDef['[ParseError]']) {
|
|
1475
1481
|
throw `argDef [ParseError] ${argDef['[ParseError]']}`
|
|
1476
1482
|
}
|
|
1483
|
+
|
|
1484
|
+
let scriptArgs = await getScriptArgs(argDef, enrichArgs(str.replace(/^\d+\s*/, '')));
|
|
1485
|
+
process.argv = [process.argv[0], path, ...(scriptArgs.map(String))]
|
|
1486
|
+
return await evalText(text, uniqueName, scriptArgs)
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
async function runScript(uniqueName, oriArgs) {
|
|
1490
|
+
let path = getFullPath(uniqueName);
|
|
1491
|
+
let text = String(_fs.readFileSync(path))
|
|
1492
|
+
let argDef = getArgDef(text)
|
|
1493
|
+
let scriptArgs = await getScriptArgs(argDef, oriArgs);
|
|
1494
|
+
process.argv = [process.argv[0], path, ...(scriptArgs.map(String))]
|
|
1495
|
+
return await evalText(text, uniqueName, scriptArgs)
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
async function getScriptArgs(argDef, oriArgs) {
|
|
1499
|
+
let shortDefMap = getShortDefMap(Object.keys(argDef))
|
|
1500
|
+
oriArgs = oriArgs.map(i => shortDefMap[i] ? shortDefMap[i]:i)
|
|
1477
1501
|
let argNames = Object.keys(argDef)
|
|
1478
1502
|
let exactArgs = {}
|
|
1479
1503
|
let scriptArgs = []
|
|
@@ -1481,9 +1505,12 @@ async function runCmd(str = '', uniqueName = '', text = '') {
|
|
|
1481
1505
|
let arg = oriArgs[i]
|
|
1482
1506
|
let needTrans
|
|
1483
1507
|
let pair
|
|
1508
|
+
if (arg.startsWith("-") && !arg.endsWith(' ')) {
|
|
1509
|
+
throw 'invalid argName ' + arg
|
|
1510
|
+
}
|
|
1484
1511
|
if (arg.startsWith(":") || arg.startsWith("_") && !arg.endsWith(' ')) {
|
|
1485
1512
|
arg = arg.replace(/^:/, '')
|
|
1486
|
-
if (oriArgs[i+1] && !(oriArgs[i+1].startsWith(":") || oriArgs[i+1].startsWith("_"))) {
|
|
1513
|
+
if (oriArgs[i+1] && (oriArgs[i+1].endsWith(' ') || !(oriArgs[i+1].startsWith(":") || oriArgs[i+1].startsWith("_")))) {
|
|
1487
1514
|
pair = [arg, oriArgs[i+1]]
|
|
1488
1515
|
i++
|
|
1489
1516
|
} else {
|
|
@@ -1539,16 +1566,13 @@ async function runCmd(str = '', uniqueName = '', text = '') {
|
|
|
1539
1566
|
if (argAbsent) {
|
|
1540
1567
|
throw 'invalid args';
|
|
1541
1568
|
}
|
|
1542
|
-
|
|
1543
|
-
process.argv = [process.argv[0], path, ...(scriptArgs.map(String))]
|
|
1544
|
-
return await evalText(text, uniqueName, scriptArgs)
|
|
1569
|
+
return scriptArgs;
|
|
1545
1570
|
}
|
|
1546
1571
|
|
|
1547
1572
|
// 使用空格作为可执行的标志
|
|
1548
1573
|
function enrichArgs(str) {
|
|
1549
1574
|
let args = []
|
|
1550
1575
|
let temp = []
|
|
1551
|
-
str = str.replace(/^\d+\s*/, '')
|
|
1552
1576
|
regEach(str, /'([^']*)'|"([^"]*)"|`([^`]*)`/g, item => {
|
|
1553
1577
|
if (item[1] !== null && item[1] !== undefined) {
|
|
1554
1578
|
temp.push(trim(item[1]) + ' ')
|