Skip to content

Commit 54badc6

Browse files
authored
Merge pull request #236 from OpenAF/t8
T8
2 parents 9b9d77f + 934d918 commit 54badc6

File tree

4 files changed

+59
-17
lines changed

4 files changed

+59
-17
lines changed

js/openaf.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2367,6 +2367,20 @@ function beep() {
23672367
Packages.java.awt.Toolkit.getDefaultToolkit().beep();
23682368
}
23692369

2370+
/**
2371+
* <odoc>
2372+
* <key>objOrStr(aObj, aStr) : String</key>
2373+
* Given aObj (a map or an array) will try to assess if aStr is an aObj key (using $$.get).
2374+
* If yes, it will return the corresponding aObj value otherwise it will return aStr.
2375+
* </odoc>
2376+
*/
2377+
function objOrStr(aObj, aStr) {
2378+
if (!isMap(aObj) && !isArray(aObj)) return aStr;
2379+
var r = $$(aObj).get(aStr);
2380+
if (isUnDef(r)) r = aStr;
2381+
return r;
2382+
}
2383+
23702384
/**
23712385
* <odoc>
23722386
* <key>watch(waitFor, aCommand, beautifyFlag, noPrint)</key>

js/openafconsole.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var CONSOLESEPARATOR = "-- ";
1010
var CONSOLESEPARATOR_ANSI = "── ";
1111
var CONSOLEHISTORY = ".openaf-console_history";
1212
var CONSOLEPROFILE = ".openaf-console_profile";
13-
var RESERVEDWORDS = "help|exit|time|output|beautify|desc|scope|alias|color|watch|clear|purge|pause|table|view|sql|esql|dsql|pin|multi";
13+
var RESERVEDWORDS = "help|exit|time|output|beautify|desc|scope|alias|color|watch|clear|purge|pause|table|view|sql|esql|dsql|pin|multi|diff";
1414
var __alias = {
1515
"opack": "oPack(__aliasparam);",
1616
"encryptText": "print(\"Encrypted text: \" + askEncrypt(\"Enter text: \"));",

js/owrap.format.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,9 @@ OpenWrap.format.prototype.toSLON = function(aObj, cTheme) {
882882

883883
if (isMap(cTheme)) dTheme = merge(dTheme, cTheme);
884884

885+
if (isNull(aObj)) {
886+
return null;
887+
}
885888
if (isMap(aObj)) {
886889
var pairs = [];
887890
Object.keys(aObj).forEach(r => {
@@ -897,7 +900,7 @@ OpenWrap.format.prototype.toSLON = function(aObj, cTheme) {
897900
if (isDate(aObj)) {
898901
return ow.format.fromDate(aObj, 'yyyy-MM-dd/HH:mm:ss.SSS');
899902
}
900-
if (!isMap(aObj) && !isArray(aObj)) return isString(aObj) ? dTheme.strQuote + aObj + dTheme.strQuote : aObj;
903+
if (!isMap(aObj) && !isArray(aObj)) return (isString(aObj) ? dTheme.strQuote + aObj + dTheme.strQuote : String(aObj));
901904
}
902905

903906
/**

js/owrap.oJob.js

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -958,11 +958,11 @@ OpenWrap.oJob.prototype.__addLog = function(aOp, aJobName, aJobExecId, args, anE
958958
try {
959959
//var execJob = $path(existing.log, "[?id==`" + currentJobExecId + "`] | @[0]");
960960
var execJob = $from(existing.log).useCase(true).equals("id", currentJobExecId).at(0);
961-
if (isDef(anException) && isDef(anException.javaException)) {
961+
if (isDef(anException) && isDef(anException.javaException) && this.__ojob.logArgs) {
962962
var ar = anException.javaException.getStackTrace();
963-
execJob.error = [ String(anException.javaException) ];
964-
for(var er in ar) {
965-
execJob.error.push(" at "+ ar[er]);
963+
execJob.error = [ String(anException.javaException) ];
964+
for(var er in ar) {
965+
execJob.error.push(" at "+ ar[er]);
966966
}
967967
} else {
968968
execJob.error = String(anException);
@@ -1067,6 +1067,7 @@ OpenWrap.oJob.prototype.__addLog = function(aOp, aJobName, aJobExecId, args, anE
10671067
// Housekeeping
10681068
while (existing.log.length > this.__logLimit) existing.log.shift();
10691069

1070+
if (!this.__ojob.logArgs) delete existing.args;
10701071
this.getLogCh().set({ "ojobId": this.__id + aId, "name": aJobName }, existing);
10711072
}
10721073

@@ -1514,19 +1515,28 @@ OpenWrap.oJob.prototype.runJob = function(aJob, provideArgs, aId, noAsync, rExec
15141515
var useExt = true, recordError = true;
15151516
if (isDef(fint)) {
15161517
if (!fint(aValue, job, id, depInfo, e)) {
1517-
errors.push(stringify({ args: aValue, exception: e}));
1518+
if (parent.__ojob.logArgs)
1519+
errors.push(stringify({ args: aValue, exception: e}));
1520+
else
1521+
errors.push(stringify({ exception: e }));
15181522
}
15191523
recordError = false;
15201524
useExt = false;
15211525
}
15221526
if (isDef(fe) && useExt) {
15231527
if (!fe(aValue, job, id, depInfo, e)) {
1524-
errors.push(stringify({ args: aValue, exception: e}));
1528+
if (parent.__ojob.logArgs)
1529+
errors.push(stringify({ args: aValue, exception: e}));
1530+
else
1531+
errors.push(stringify({ exception: e}));
15251532
}
15261533
recordError = false;
15271534
}
15281535
if (recordError) {
1529-
errors.push(stringify({ args: aValue, exception: e}));
1536+
if (parent.__ojob.logArgs)
1537+
errors.push(stringify({ args: aValue, exception: e}));
1538+
else
1539+
errors.push(stringify({ exception: e}));
15301540
}
15311541
} finally {
15321542
return true;
@@ -1542,19 +1552,28 @@ OpenWrap.oJob.prototype.runJob = function(aJob, provideArgs, aId, noAsync, rExec
15421552
var useExt = true, recordError = true;
15431553
if (isDef(fint)) {
15441554
if (!fint(args.__oJobRepeat[aVi], job, id, depInfo, e)) {
1545-
errors.push(stringify({ args: args.__oJobRepeat[aVi], exception: e}));
1555+
if (parent.__ojob.logArgs)
1556+
errors.push(stringify({ args: args.__oJobRepeat[aVi], exception: e}));
1557+
else
1558+
errors.push(stringify({ exception: e}));
15461559
}
15471560
recordError = false;
15481561
useExt = false;
15491562
}
15501563
if (isDef(fe) && useExt) {
15511564
if (!fe(args.__oJobRepeat[aVi], job, id, depInfo, e)) {
1552-
errors.push(stringify({ args: args.__oJobRepeat[aVi], exception: e}));
1565+
if (parent.__ojob.logArgs)
1566+
errors.push(stringify({ args: args.__oJobRepeat[aVi], exception: e}));
1567+
else
1568+
errors.push(stringify({ exception: e}));
15531569
}
15541570
recordError = false;
15551571
}
15561572
if (recordError) {
1557-
errors.push(stringify({ args: args.__oJobRepeat[aVi], exception: e}));
1573+
if (parent.__ojob.logArgs)
1574+
errors.push(stringify({ args: args.__oJobRepeat[aVi], exception: e}));
1575+
else
1576+
errors.push(stringify({ exception: e}));
15581577
}
15591578
}
15601579
}
@@ -1892,7 +1911,7 @@ OpenWrap.oJob.prototype.addJob = function(aJobsCh, _aName, _jobDeps, _jobType, _
18921911
}
18931912
var prefix = "";
18941913
if (isString(aJobTypeArgs.shellPrefix)) {
1895-
prefix = ".prefix(\"" + aJobTypeArgs.shellPrefix + "\")";
1914+
prefix = ".prefix(objOrStr(args, \"" + parent.__processTypeArg(aJobTypeArgs.shellPrefix) + "\"))";
18961915
}
18971916
res += "var __uuid = '.' + genUUID() + '.bat'; _$(args.ssh, 'ssh').isMap().$_(); var __res = $ssh(args.ssh).putFile(ft, __uuid).sh(" + stringify(aJobTypeArgs.shell) + " + ' ' + __uuid)" + prefix + ".exit((r, s)=>s.rm(__uuid)).get(0); io.rm(ft);\n";
18981917
res += "if (!isNull(__res.stdout)) if (isMap(jsonParse(__res.stdout, true))) { args = merge(args, jsonParse(__res.stdout, true)) } else { if (__res.stdout.length > 0) { printnl(__res.stdout) }; if (__res.stderr.length > 0) { printErrnl(__res.stderr); } }";
@@ -1903,7 +1922,7 @@ OpenWrap.oJob.prototype.addJob = function(aJobsCh, _aName, _jobDeps, _jobType, _
19031922
if (!(res.indexOf("/* __oaf_ojob shell */") >= 0)) {
19041923
var prefix = "";
19051924
if (isString(aJobTypeArgs.shellPrefix)) {
1906-
prefix = ".prefix(\"" + aJobTypeArgs.shellPrefix + "\")";
1925+
prefix = ".prefix(objOrStr(args, \"" + parent.__processTypeArg(aJobTypeArgs.shellPrefix) + "\"))";
19071926
}
19081927
if (ow.format.isWindows() && isUnDef(aJobTypeArgs.shell)) {
19091928
var orig = String(res);
@@ -1951,7 +1970,7 @@ OpenWrap.oJob.prototype.addJob = function(aJobsCh, _aName, _jobDeps, _jobType, _
19511970
var orig = String(res);
19521971
var prefix = "";
19531972
if (isString(aJobTypeArgs.shellPrefix)) {
1954-
prefix = ".prefix(\"" + aJobTypeArgs.shellPrefix + "\")";
1973+
prefix = ".prefix(objOrStr(args, \"" + parent.__processTypeArg(aJobTypeArgs.shellPrefix) + "\"))";
19551974
}
19561975
res = "/* __oaf_ojob shell */ ";
19571976
if (aJobTypeArgs.noTemplate) {
@@ -2104,9 +2123,9 @@ OpenWrap.oJob.prototype.addTodo = function(aOJobID, aJobsCh, aTodoCh, aJobName,
21042123

21052124
/**
21062125
* <ojob>
2107-
* <key>ow.oJob.output(aObj, args, aFunc)</key>
2126+
* <key>ow.oJob.output(aObj, args, aFunc) : Map</key>
21082127
* Tries to output aObj in different ways give the args provided. If args.__format or args.__FORMAT is provided it will force
2109-
* displaying values as "json", "yaml", "table", "map", "pm" (on the __pm variable with _list, _map or result) or "human". In "human" it will use the aFunc
2128+
* displaying values as "json", "prettyjson", "slon", "yaml", "table", "map", "pm" (on the __pm variable with _list, _map or result) or "human". In "human" it will use the aFunc
21102129
* provided or a default that tries printMap or sprint. If a format isn't provided it defaults to human or global.__format if defined.
21112130
* </ojob>
21122131
*/
@@ -2128,6 +2147,12 @@ OpenWrap.oJob.prototype.output = function(aObj, args, aFunc) {
21282147
case "json":
21292148
sprint(aObj, "");
21302149
break;
2150+
case "prettyjson":
2151+
sprint(aObj);
2152+
break;
2153+
case "slon":
2154+
print(ow.format.toSLON(aObj));
2155+
break;
21312156
case "yaml":
21322157
yprint(aObj);
21332158
break;

0 commit comments

Comments
 (0)