-
Notifications
You must be signed in to change notification settings - Fork 6
/
ojob.json
executable file
·1 lines (1 loc) · 61.8 KB
/
ojob.json
1
{"jobs":[{"name":"ojob pass","typeArgs":{"noLog":true,"shortcut":{"name":"pass","keyArg":"__args","args":{"debug":"__debug","templateArgs":"__templateArgs"}}},"help":{"text":"Placeholder/pass job to allow for arguments injection","expects":[{"name":"__args","desc":"The args to inject"},{"name":"__debug","desc":"Boolean to indicate that args to be inject should be printed before"},{"name":"__templateArgs","desc":"Boolean, true by default, to indicate to apply template to each string in args (use only if typeArgs.noTemplateArgs = false OR job.templateArgs = true)"}]},"check":{"in":{"__args":"isMap.default({})","__debug":"toBoolean.isBoolean.default(false)","__templateArgs":"toBoolean.isBoolean.default(true)"}},"exec":"var b=clone(args.__args);args.__templateArgs?traverse(b,function(c,a,e,d){isNull(a)&&(d[c]=__);isString(a)&&0<=a.indexOf(\"{{\")&&(d[c]=templify(a,args))}):traverse(b,function(c,a,e,d){isNull(a)&&(d[c]=__)});args.__debug&&cprint(ow.format.withSideLine(printTreeOrS(b,__,{bgcolor:\"BG(235)\"}),__,\"FG(240)\",\"BG(235)\",ow.format.withSideLineThemes().openBottomCurvedRect));delete args.__argsp;delete args.__debug;delete args.__templateArgs;args=merge(args,b)"},{"name":"ojob debug","typeArgs":{"noLog":true,"shortcut":{"name":"jobdebug","keyArg":"job","args":{"lineColor":"lineColor","textColor":"textColor","theme":"theme","emoticons":"emoticons","signs":"signs","includeTime":"includeTime"}}},"help":{"text":"Outputs the current args and res values to help debug an ojob flow."},"exec":"ow.loadFormat();print(\"\");cprint(ow.format.withSideLine(\"ARGS:\",__,\"FG(240)\",\"BG(240),BOLD\",ow.format.withSideLineThemes().openBottomCurvedRect));cprint(ow.format.withSideLine(colorify(args,{bgcolor:\"BG(235)\"}),__,\"FG(240)\",\"BG(235)\",ow.format.withSideLineThemes().openTopCurvedRect));cprint(ow.format.withSideLine(\"RES:\",__,\"FG(240),BOLD\",\"BG(240),BOLD\",ow.format.withSideLineThemes().openBottomCurvedRect));cprint(ow.format.withSideLine(colorify($get(\"res\"),{bgcolor:\"BG(235)\"}),__,\"FG(240)\",\n\"BG(235)\",ow.format.withSideLineThemes().openTopCurvedRect))"},{"name":"ojob job debug","typeArgs":{"noLog":true,"shortcut":{"name":"jobsdebug","keyArg":"jobs","args":{"lineColor":"lineColor","textColor":"textColor","theme":"theme","emoticons":"emoticons","signs":"signs","includeTime":"includeTime"}}},"help":{"text":"Provides an alternative to print based debug.\n\nExample:\n # ----------------\n - name: Sample job\n exec: |\n //@ Declaring array\n var ar = [ 0, 1, 2, 3, 4, 5 ]\n\n //@ Start cycle\n var ii = 0;\n while(ii < ar.length) {\n print(\"II = \" + ii)\n ii++\n //# ii == 3\n }\n //@ End cycle\n //? ii\n\n //?s args\n //?y args\n","expects":[{"name":"job","desc":"The job to change to include debug"},{"name":"jobs","desc":"The jobs array to change to include debug"},{"name":"lineColor","desc":"The line color around the debug info"},{"name":"textColor","desc":"The text color around the debug info"},{"name":"theme","desc":"The withSideLineThemes theme to use"},{"name":"emoticons","desc":"If emoticons should be used or not"},{"name":"signs","desc":"A custom map of emoticons (keys: checkpoint, assert and print)"},{"name":"includeTime","desc":"A boolean value to indicate if a time indication should be included"}]},"check":{"in":{"job":"isString.default(__)","jobs":"isArray.default([])","lineColor":"isString.default(\"FG(220)\")","textColor":"isString.default(\"BG(230),BLACK\")","lineError":"isString.default(\"FG(220)\")","textError":"isString.default(\"BG(196),FG(255),BOLD\")","theme":"isString.default(\"doubleLineBothSides\")","emoticons":"toBoolean.isBoolean.default(true)","signs":"isMap.default(__)","includeTime":"toBoolean.isBoolean.default(false)"}},"exec":"isMap(void 0)&&(args=merge(void 0,args));args.signs=_$(args.signs,\"signs\").isMap().default({checkpoint:127866,assert:128077,print:128270,error:128545,time:\"\\ud83d\\udd52\"});isDef(args.job)&&0==args.jobs.length&&args.jobs.push(args.job);if(isUnDef(getEnv(\"OJOB_DEBUG\"))||toBoolean(getEnv(\"OJOB_DEBUG\"))){ow.loadFormat();var h=ow.oJob.getJobsCh();0==args.jobs.length&&(args.jobs=h.getKeys().filter(function(e){return\"ojob job debug\"!=e.name}).map(function(e){return e.name}));var k=!1;isDef(ow.loadDebug)&&\n(ow.loadDebug(),ow.debug.register(),k=!0);args.jobs.forEach(function(e){var d=h.get({name:e});if(k){if(isUnDef(d.lang)||isDef(d.lang)&&(\"oaf\"==d.lang||\"js\"==d.lang))d.exec=ow.debug.debug(d.exec,args,!0)}else{var f=function(c,a){var g=\";try{\";isDef(a)&&(g+=\"if(\"+a+\") {\");var l=args.includeTime?'(new Date()).toISOString() +\" | \" + ':\"\";g+=\"cprint(ow.format.withSideLine(\"+l+c+', __, \"'+args.lineColor+'\", \"'+args.textColor+'\", ow.format.withSideLineThemes().'+args.theme+\")) \";isDef(a)&&(g+=\"}\");return g+=\n\"}catch(__e_debug){cprint(ow.format.withSideLine(\"+l+\"' \"+b.error+\" ' + String(__e_debug), __, \\\"\"+args.lineError+'\", \"'+args.textError+'\", ow.format.withSideLineThemes().'+args.theme+\"))};\"};if(args.emoticons){var b=args.signs;isNumber(b.checkpoint)&&(b.checkpoint=ow.format.string.unicode(b.checkpoint));isNumber(b.assert)&&(b.assert=ow.format.string.unicode(b.assert));isNumber(b.print)&&(b.print=ow.format.string.unicode(b.print));isNumber(b.error)&&(b.error=ow.format.string.unicode(b.error))}b.checkpoint=\n_$(b.checkpoint).default(\"@\");b.assert=_$(b.assert).default(\"#\");b.print=_$(b.print).default(\"?\");b.error=_$(b.error).default(\"!\");d.exec=d.exec.split(\"\\n\").map(function(c){var a=c.trim().match(/\\/\\/@ (.+)$/);isArray(a)&&(a=a[1],c=c.replace(/\\/\\/@ (.+)$/,f('\" '+b.checkpoint+\" \"+a.replace(/\"/g,'\\\\\"')+'\"')));a=c.trim().match(/\\/\\/# (.+)$/);isArray(a)&&(a=a[1],c=c.replace(/\\/\\/# (.+)$/,f('\" '+b.assert+\" \"+a+'\"',a)));a=c.trim().match(/\\/\\/\\? (.+)$/);isArray(a)&&(a=a[1],c=c.replace(/\\/\\/\\? (.+)$/,f('\" '+\nb.print+\" \"+a+' = \" + stringify('+a+') + \"\"')));a=c.trim().match(/\\/\\/\\?s (.+)$/);isArray(a)&&(a=a[1],c=c.replace(/\\/\\/\\?s (.+)$/,f('\" '+b.print+\" \"+a+' = \" + af.toSLON('+a+') + \"\"')));a=c.trim().match(/\\/\\/\\?y (.+)$/);isArray(a)&&(a=a[1],c=c.replace(/\\/\\/\\?y (.+)$/,f('\" '+b.print+\" \"+a+' = \" + af.toYAML('+a+') + \"\"')));return c}).join(\"\\n\")}h.set({name:e},d)})}"},{"name":"ojob get pm","args":{"__key":"args"},"check":{"in":{"__key":"isString.default(\"res\")"}},"exec":"var a=__pm;isDef(__pm._map)&&(a=__pm._map);isDef(__pm._list)&&(a=__pm._list);\"args\"==args.__key?args=merge(args,a):$set(args.__key,a);Object.keys(args).filter(function(b){return b.startsWith(\"__\")}).forEach(function(b){return delete args[b]})"},{"name":"ojob get","typeArgs":{"shortcut":{"name":"get","keyArg":"__key","args":{"path":"__path"}}},"help":{"text":"Retrieves a specific map key (or path) using $get","expects":[{"name":"__key","desc":"Map key to retrieve (key is also checked for compatibility)"},{"name":"__path","desc":"The path to consider from the __key"}]},"check":{"in":{"__key":"isString.default(\"res\")","__path":"isString.default(\"@\")"}},"exec":"isUnDef(args.__key)&&isDef(args.key)&&(args.__key=args.key);var a=\"args\"==args.__key?$path(args,args.__path):$path($get(args.__key),args.__path);isArray(a)&&(a={_list:a});args=merge(args,a);Object.keys(args).filter(function(b){return b.startsWith(\"__\")}).forEach(function(b){return delete args[b]})"},{"name":"ojob set","typeArgs":{"shortcut":{"name":"set","keyArg":"__key","args":{"path":"__path"}}},"help":{"text":"Sets a \"key\" with the current value on a \"path\" using $set","expects":[{"name":"__key","desc":"Map key"},{"name":"__path","desc":"A key or path to a value from the current args"}]},"check":{"in":{"__key":"isString.default(\"res\")","__path":"isString"}},"exec":"var b=$path(args,args.__path);isDef(b)&&\"args\"!=args.__key&&$set(args.__key,b);Object.keys(args).filter(function(a){return a.startsWith(\"__\")}).forEach(function(a){return delete args[a]})"},{"name":"ojob unset","typeArgs":{"shortcut":{"name":"unset","keyArg":"__key"}},"help":{"text":"Unsets a \"key\" using $unset","expects":[{"name":"__key","desc":"Map key"}],"check":{"in":{"__key":"isString.default(\"res\")"}}},"exec":"$unset(args.__key);Object.keys(args).filter(function(a){return a.startsWith(\"__\")}).forEach(function(a){return delete args[a]})"},{"name":"ojob file get","typeArgs":{"noLog":true,"shortcut":{"name":"fileget","keyArg":"__file","args":{"path":"__path","cache":"__cache","ttl":"__ttl","out":"__out","key":"__key"}}},"help":{"text":"Retrieves a specific map key (or path) from an YAML or JSON file provided.","expects":[{"name":"__file","desc":"The file path to an YAML or JSON file","required":true},{"name":"__path","desc":"Path of the file contents"},{"name":"__cache","desc":"Boolean value that if false it won't cache the file contents (default: true)"},{"name":"__ttl","desc":"If cache is enabled lets you define a numeric ttl"},{"name":"__out","desc":"The path on args to set the map key/path contents"},{"name":"__key","desc":"If __out is not defined will set the content into the provided key"}]},"check":{"in":{"__file":"isString","__path":"isString.default(\"@\")","__cache":"toBoolean.isBoolean.default(true)","__ttl":"isNumber.default(__)","__out":"isString.default(__)","__key":"isString.default(\"res\")"}},"exec":"if(args.__cache){var c=$cache(\"__ojob_file_get\");isDef(args.__ttl)&&(c=c.ttl(args.__ttl));c=c.fn(function(a){return isDef(a.file)?a.file.endsWith(\".json\")?io.readFileJSON(a.file):/\\.ya?ml$/.test(a.file)?io.readFileYAML(a.file):{error:\"Not an yaml, yml or json file.\"}:{}}).create();var b=c.get({file:args.__file})}else b=args.__file.endsWith(\".json\")?io.readFileJSON(args.__file):/\\.ya?ml$/.test(args.__file)?io.readFileYAML(args.__file):{error:\"Not an yaml, yml or json file.\"};b=$path(b,\nargs.__path);isDef(args.__out)?$$(args).set(args.__out,b):isDef(args.__key)?$set(args.__key,b):Object.keys(b).forEach(function(a){return $$(args).set(a,b[a])});Object.keys(args).filter(function(a){return a.startsWith(\"__\")}).forEach(function(a){return delete args[a]})"},{"name":"ojob template","typeArgs":{"shortcut":{"name":"template","keyArg":"template","args":{"templateFile":"templateFile","data":"data","dataFile":"dataFile","outputFile":"outputFile","key":"__key","tpath":"__tpath","dpath":"__dpath","outPath":"__outPath","out":"__out"}}},"help":{"text":"Applies the OpenAF template over the provided data producing an output.","expects":[{"name":"__key","desc":"The key that holds template and/or data (default to 'res'). If 'args' it will use the current arguments."},{"name":"__tpath","desc":"The path in __key where a string with the template can be found."},{"name":"__dpath","desc":"The path in __key where a map/array data to use can be found."},{"name":"__out","desc":"The output will be stored into the provided key (defaults to 'res')"},{"name":"__outPath","desc":"If defined the $set path where __out will be set in the provided key."},{"name":"template","desc":"If defined, will be used as template"},{"name":"templateFile","desc":"If defined, it will use the provided template file."},{"name":"data","desc":"If defined, will be used as data"},{"name":"dataFile","desc":"If defined, it will use the provided data file (either yaml or json)."},{"name":"outputFile","desc":"If defined, the output will be written to the provided file path."}],"returns":[{"name":"output","desc":"If no outputFile is provided this will hold the output of applying the template with the provided data"}]},"check":{"in":{"__key":"isString.default(\"res\")","__tpath":"isString.default(\"@\")","__dpath":"isString.default(\"@\")","__out":"isString.default(\"res\")","__outPath":"isString.default(\"\")","templateFile":"isString.default(__)","dataFile":"isString.default(__)","outputFile":"isString.default(__)"}},"exec":"ow.loadTemplate();ow.template.addConditionalHelpers();ow.template.addFormatHelpers();ow.template.addOpenAFHelpers();var a=isDef(args.data)?args.data:\"args\"==args.__key?$path(args,args.__dpath):$path($get(args.__key),args.__dpath);isDef(args.dataFile)&&(a=args.dataFile.match(/\\.ya?ml$/i)?io.readFileYAML(args.dataFile):io.readFileJSON(args.dataFile));var b=isDef(args.template)?args.template:\"args\"==args.__key?$path(args,args.__tpath):$path($get(args.__key),args.__tpath);isDef(args.templateFile)&&\n(b=io.readFileString(args.templateFile));isDef(args.logJob)&&$job(args.logJob,args);a=templify(b,a);isDef(args.outputFile)?io.writeFileString(args.outputFile,a):\"args\"==args.__out?isDef(args.__outPath)&&0<args.__outPath.length?$$(args).set(args.__outPath,a):args.output=a:(b={},isDef(args.__outPath)&&0<args.__outPath.length&&$$(b).set(args.__outPath,a),b.output=a,$set(args.__out,b))"},{"name":"ojob template folder","typeArgs":{"shortcut":{"name":"templateFolder","keyArg":"templateFolder","args":{"templatePath":"__templatePath","data":"data","dataFile":"dataFile","outputFolder":"outputFolder","key":"__key","dpath":"__dpath","logJob":"logJob","metaTemplate":"metaTemplate"}}},"help":{"text":"Given a templateFolder it will execute 'ojob template' for each (recursively), with the provided data, to output to outputFolder. Optionally metaTemplate can be use where each json/yaml file in templateFolder all or part of the arguments for 'ojob template'.\n","expects":[{"name":"templateFolder","desc":"The original folder where the templates are located.","required":true},{"name":"__templatePath","desc":"If defined, will apply a $path string over the recursive list of files in templateFolder."},{"name":"outputFolder","desc":"The path where the output should be stored.","required":true},{"name":"data","desc":"If defined, will be used as data"},{"name":"dataFile","desc":"If defined, it will use the provided data file (either yaml or json)."},{"name":"__key","desc":"The key that holds template and/or data (default to 'res'). If 'args' it will use the current arguments."},{"name":"__dpath","desc":"The path in __key where a map/array data to use can be found."},{"name":"logJob","desc":"A ojob job to log the 'ojob template' activity (receives the same arguments as 'ojob template')"},{"name":"metaTemplate","desc":"Boolean that if 'true' will interpret any json/yaml file, in the templateFolder, as a map/array of arguments to use when calling 'ojob template' overriden the defaults."}]},"check":{"in":{"templateFolder":"isString","__templatePath":"isString.default(\"@\")","outputFolder":"isString","dataFile":"isString.default(__)","__key":"isString.default(\"res\")","__dpath":"isString.default(\"@\")","logJob":"isString.default(__)","metaTemplate":"toBoolean.isBoolean.default(false)"}},"exec":"var e=isDef(args.data)?args.data:\"args\"==args.__key?$path(args,args.__dpath):$path($get(args.__key),args.__dpath);isDef(args.dataFile)&&(e=args.dataFile.match(/\\.ya?ml$/i)?io.readFileYAML(args.dataFile):io.readFileJSON(args.dataFile));var b=[];$path(listFilesRecursive(args.templateFolder),args.__templatePath).forEach(function(a){var d={templateFile:a.filepath,outputFile:a.filepath.replace(new RegExp(\"^\"+args.templateFolder),args.outputFolder),data:e,logJob:args.logJob};args.metaTemplate&&\na.filename.match(/\\.(ya?ml|json)$/i)?(a=a.filename.match(/\\.ya?ml$/i)?io.readFileYAML(a.filepath):io.readFileJSON(a.filepath),delete d.templateFile,isMap(a)&&(isDef(a.outputFile)&&!a.outputFile.startsWith(\"/\")&&(a.outputFile=args.outputFolder+\"/\"+a.outputFile),b.push(merge(d,a))),isArray(a)&&(b=b.concat(a.map(function(c){isDef(c.outputFile)&&!c.outputFile.startsWith(\"/\")&&(c.outputFile=args.outputFolder+\"/\"+c.outputFile);return merge(d,c)})))):b.push(d)});io.mkdir(args.outputFolder);$job(\"ojob template\",\nb)"},{"name":"ojob find/replace","typeArgs":{"noLog":true,"shortcut":{"name":"findReplace","keyArg":"__key","args":{"path":"__path","inputKey":"inputKey","inputPath":"inputPath","inputFile":"inputFile","outputFile":"outputFile","useRegExp":"useRegExp","flagsRegExp":"flagsRegExp","logJob":"logJob"}}},"help":{"text":"Performs an in-memory find/replace on a provided string or file and outputs to args.output or, optionally, to a file.","expects":[{"name":"__key","desc":"The key that holds template and/or data (default to 'res'). If 'args' it will use the current arguments."},{"name":"__path","desc":"The path in __key where a map of replacements ([text/regexp]:[replace text]) can be found."},{"name":"inputKey","desc":"If defined, indicates the key that holds the string of data to replace."},{"name":"inputPath","desc":"If defined with inputKey, indicates the path to use to select the string of data to replace."},{"name":"inputFile","desc":"If defined the contents to be replaced will be read from the inputFile."},{"name":"outputFile","desc":"If defined will output of the content replacement to the defined file."},{"name":"useRegExp","desc":"Boolean value to determine if the map of replacements will be interpreted as a regexp or text."},{"name":"flagsRegExp","desc":"If useRegExp=true the JavaScript reg exp flags to use (defaults to 'g')"},{"name":"logJob","desc":"Optionally provide a logging job with the current args and __op with 'read' or 'write'"}],"returns":[{"name":"output","desc":"If outputFile is not defined the output will contain the content replacement"}]},"check":{"in":{"__key":"default(\"res\")","__path":"isString.default(\"@\")","inputKey":"isString.default(__)","inputPath":"isString.default(__)","inputFile":"isString.default(__)","outputFile":"isString.default(__)","useRegExp":"toBoolean.isBoolean.default(false)","flagsRegExp":"isString.default(\"g\")","logJob":"default(__)"}},"exec":"var b=isMap(args.__key)?args.__key:$path(\"args\"==args.__key?args:$get(args.__key),args.__path);_$(b,\"__key data\").isMap().$_();if(isUnDef(args.inputKey)&&isUnDef(args.inputFile))throw\"Need args inputKey or inputFile\";args.__op=\"read\";isDef(args.logJob)&&$job(args.logJob,args);var a=isDef(args.inputKey)?$path(\"args\"==args.inputKey?args:$get(args.inputKey),args.inputPath):io.readFileString(args.inputFile);Object.keys(b).forEach(function(c){a=a.replace(new RegExp(args.useRegExp?c:c.replace(/[.*+?^${}()|[\\]\\\\]/g,\n\"\\\\$&\"),args.useRegExp?args.flagsRegExp:\"g\"),b[c])});args.__op=\"write\";isDef(args.logJob)&&$job(args.logJob,args);isDef(args.outputFile)?io.writeFileString(args.outputFile,a):args.output=a"},{"name":"ojob channel","typeArgs":{"shortcut":{"name":"ch","keyArg":"__name","args":{"op":"__op","key":"__key","kpath":"__kpath","k":"key","ks":"keys","v":"value","vs":"values","vpath":"__vpath","extra":"extra"}}},"help":{"text":"Provides a set of operations over an OpenAF channel","expects":[{"name":"__name","desc":"The name of the OpenAF channel to use","required":true},{"name":"__op","desc":"The operation to perform (e.g. setall, set, get, unset, unsetall, getkeys, getall and size)","required":true},{"name":"__key","desc":"The key from where to retrieve the operation arguments (args to retrive from arguments)"},{"name":"__kpath","desc":"If defined, the path over the values retrieved from __key where the key or keys of the operation are defined"},{"name":"key","desc":"If defined, the key to use with the operations set, get and unset"},{"name":"keys","desc":"If defined, the set of fields to use with the operations setall and unsetall"},{"name":"value","desc":"If defined, the value to use with the operations set, get and unset"},{"name":"values","desc":"If defined, an array of values to use with the operations setall and unsetall"},{"name":"__vpath","desc":"If defined, the path over the values retrieved from __key where the value or values of the operation are defined"},{"name":"extra","desc":"If defined, will provide an extra argument (usually a map), depending on channel type, for the getall and getkeys operations."}],"returns":[{"name":"_list","desc":"If __key == 'args' will return the results of getall and getkeys"},{"name":"_map","desc":"If __key == 'args' will return the results of get"},{"name":"size","desc":"If __key == 'args' will return the size of the channel"}]},"check":{"in":{"__name":"isString","__op":"isString","key":"default(__)","keys":"default(__)","value":"default(__)","values":"default(__)","__kpath":"isString.default(__)","__vpath":"isString.default(__)","extra":"default(__)","__key":"default(\"res\")"}},"exec":"var a=function(){var b={k:__,v:__};isDef(args.key)&&(b.k=args.key);isDef(args.keys)&&(b.k=args.keys);isDef(args.value)&&(b.v=args.value);isDef(args.values)&&(b.v=args.values);\"args\"==args.__key?(isDef(args.__kpath)&&(b.k=$path(args,args.__kpath)),isDef(args.__vpath)&&(b.v=$path(args,args.__vpath))):(isDef(args.__kpath)&&(b.k=$path($get(args.__key),args.__kpath)),isDef(args.__vpath)&&(b.v=$path($get(args.__key),args.__vpath)));return b};switch(args.__op.toLowerCase()){case \"getall\":a=$ch(args.__name).getAll(args.extra);\nisUnDef(a)&&(a=[]);\"args\"!=args.__key?$set(args.__key,a):args._list=a;break;case \"setall\":a=a();$ch(args.__name).setAll(a.k,a.v);break;case \"set\":a=a();$ch(args.__name).set(a.k,a.v);break;case \"get\":a=a();a=$ch(args.__name).get(a.k);isUnDef(a)&&(a={});\"args\"!=args.__key?$set(args.__key,a):args._map=a;break;case \"unset\":a=a();$ch(args.__name).unset(a.k);break;case \"unsetall\":a=a();$ch(args.__name).unsetAll(a.k,a.v);break;case \"getkeys\":a=$ch(args.__name).getKeys(args.extra);isUnDef(a)&&(a=[]);\"args\"!=\nargs.__key?$set(args.__key,a):args._list=a;break;case \"size\":a=$ch(args.__name).size(),isUnDef(a)&&(a=-1),\"args\"!=args.__key?$set(args.__key,a):args.size=a}"},{"name":"ojob print","typeArgs":{"noLog":true,"shortcut":{"name":"print","keyArg":"msg","args":{"key":"__key","path":"__path","level":"level"}}},"help":{"text":"Prints a message line given an OpenAF template","expects":[{"name":"__key","desc":"Map key to retrieve ('args' for arguments)"},{"name":"__path","desc":"The path to consider from the __key"},{"name":"msg","desc":"The message template to use","required":true},{"name":"level","desc":"The level of the message (info (default) or error)"}]},"check":{"in":{"__key":"isString.default(\"res\")","__path":"isString.default(\"@\")","msg":"isString","level":"isString.oneOf([\"info\",\"error\"]).default(\"info\")"}},"exec":"var a=\"args\"==args.__key?$path(args,args.__path):$path($get(args.__key),args.__path);switch(args.level){case \"error\":tprintErr(args.msg,a);break;case \"info\":tprint(args.msg,a)}"},{"name":"ojob print md","typeArgs":{"noLog":true,"shortcut":{"name":"printmd","keyArg":"__text","args":{"outputMD":"__outputMD"}}},"help":{"text":"Parses an input text as simple ascii markdown","expects":[{"name":"__text","desc":"The text template to parse."},{"name":"__outputMD","desc":"A boolean flag that if true will no parse the input text"}]},"check":{"in":{"__text":"isString","__outputMD":"toBoolean.isBoolean.default(false)"}},"exec":"var a=clone(args);delete a.__text;args.__outputMD?printnl($t(args.__text,a)):printnl(ow.format.withMD($t(args.__text,a)));Object.keys(args).filter(function(b){return b.startsWith(\"__\")}).forEach(function(b){return delete args[b]})"},{"name":"ojob log","typeArgs":{"noLog":true,"shortcut":{"name":"log","keyArg":"msg","args":{"key":"__key","path":"__path","level":"level","options":"options"}}},"help":{"text":"Logs a message line given an OpenAF template","expects":[{"name":"__key","desc":"Map key to retrieve ('args' for arguments)"},{"name":"__path","desc":"The path to consider from the __key"},{"name":"msg","desc":"The message template to use","required":true},{"name":"level","desc":"The level of the message (info (default), warn or error)"},{"name":"options","desc":"Extra options to provide to the tlog* functions. See more in the help of tlog, tlogErr and tlogWarn."}]},"check":{"in":{"__key":"isString.default(\"res\")","__path":"isString.default(\"@\")","msg":"isString","level":"isString.oneOf([\"info\",\"warn\",\"error\"]).default(\"info\")","options":"isMap.default({})"}},"exec":"var a=\"args\"==args.__key?$path(args,args.__path):$path($get(args.__key),args.__path);switch(args.level){case \"warn\":tlogWarn(args.msg,a,args.options);break;case \"error\":tlogErr(args.msg,a,args.options);break;case \"info\":tlog(args.msg,a,args.options)}"},{"name":"ojob function","typeArgs":{"noLog":true,"shortcut":{"name":"fn","keyArg":"__fn","args":{"key":"__key","path":"__path","fnPath":"__fnPath"}}},"help":{"text":"Executes the provided function mapping any args to the function arguments using the odoc help available for the provided function.\nNote: accessing odoc might be slow on a first execution.\n","expects":[{"name":"__key","desc":"The key string to retrieve previous results (defaults to 'res')","required":true},{"name":"__fn","desc":"The function to execute"},{"name":"__path","desc":"If defined the args path for the function arguments to consider"},{"name":"__fnPath","desc":"If defined the args path where to set the function result"}]},"check":{"in":{"__fn":"isString","__key":"isString.default(\"res\")"}},"exec":"0>args.__fn.indexOf(\".\")&&(args.__fn=\"global.\"+args.__fn);var a=$fnM(args.__fn,isDef(args.__path)?$path(args,args.__path):args);isString(args.__fnPath)&&(a=$$({}).set(args.__fnPath,a));isString(args.__key)?$set(args.__key,a):args=merge(args,a);Object.keys(args).filter(function(b){return b.startsWith(\"__\")}).forEach(function(b){return delete args[b]})"},{"name":"ojob output","typeArgs":{"noLog":true,"shortcut":{"name":"output","keyArg":"__key","args":{"path":"__path","format":"__format","title":"__title","internal":"__internal","query":"__query","csv":"__csv","function":"__function"}}},"help":{"text":"Prints the current arguments to the console.","expects":[{"name":"__key","desc":"The key string to retrieve previous results (defaults to 'res'). If \"args\" will retrieve from current args."},{"name":"__path","desc":"A path string to a map/array over the results set on key."},{"name":"__format","desc":"The output format (e.g. see ow.oJob.output help)"},{"name":"__title","desc":"Encapsulates the output map/array with a title key."},{"name":"__internal","desc":"Boolean value that if true it will display the internal oJob entries on the arguments (default false)"},{"name":"__function","desc":"One of the OpenAF's print or log functions available"}]},"exec":"isUnDef(args.__key)&&isDef(args.key)&&(args.__key=args.key);isUnDef(args.__path)&&isDef(args.path)&&(args.__path=args.path);isUnDef(args.__format)&&isDef(args.format)&&(args.__format=args.format);isUnDef(args.__title)&&isDef(args.title)&&(args.__title=args.title);isUnDef(args.__internal)&&isDef(args.internal)&&(args.__internal=args.internal);if(isString(args.__function))if(0<=args.__function.indexOf(\"print\")||0<=args.__function.indexOf(\"log\")){if(!(0<=af.fromJavaArray(af.getScopeIds()).map(function(b){return String(b)}).indexOf(args.__function)))throw\"__function '\"+\nargs.__function+\"' not found.\";args.__function=global[args.__function]}else throw\"__function needs to be a 'print' or 'log' function\";else args.__function=__;args.__key=_$(args.__key,\"key\").isString().default(\"res\");\"\"==args.__key&&(args.__key=\"res\");var a=\"args\"==args.__key?args:$get(args.__key);isUnDef(a)&&(a=args);!isDef(a)||isNull(a)||toBoolean(args.__internal)||(delete a.objId,delete a.execid,delete a.id);isDef(args.format)&&(args.__format=args.format,delete args.format);isDef(args.__path)&&\n(a=$path(a,args.__path),delete args.__path);isMap(a)&&isDef(a._list)&&(a=a._list);isMap(a)&&isDef(a._map)&&(a=a._map);if(isDef(args.__title)){var c={};c[args.__title]=a;ow.oJob.output(c,args,args.__function)}else ow.oJob.output(a,args,args.__function);Object.keys(args).filter(function(b){return b.startsWith(\"__\")}).forEach(function(b){return delete args[b]})"},{"name":"ojob final report","to":"ojob report","type":"shutdown","help":{"text":"Outputs a jobs report (e.g. job name, status, number of executions, total time, avg time and last execution) upon ojob termination","expects":[{"name":"__format","desc":"Can be json, yaml, table (default) or any other ow.oJob.output format"}]}},{"name":"ojob final deps report","to":"ojob deps report","type":"shutdown","help":{"text":"Outputs a tree list for each defined job (excluding \"ojob *\") and a comma delimited list of dependencies with a status flag"}},{"name":"ojob deps report","help":{"text":"Outputs a tree list for each defined job (excluding \"ojob *\") and a comma delimited list of dependencies with a status flag"},"exec":"var b={};$from($ch(\"oJob::log\").getAll()).notStarts(\"name\",\"ojob \").select(function(a){b[a.name]=a.start?a.success?ansiColor(\"GREEN\",\"\\u2713\"):a.deps?a.error?ansiColor(\"RED\",\"\\u2715\"):ansiColor(\"BLUE\",\"\\u25b7\"):ansiColor(\"RED\",\"\\u2715\"):ansiColor(\"YELLOW\",\"\\u23f8\")});var c={};$from($ch(\"oJob::jobs\").getAll()).notStarts(\"name\",\"ojob \").select(function(a){c[a.name]=a.deps.map(function(d){return b[d]+\" \"+d}).join(\", \")});ow.oJob.output(c,{__format:\"tree\"})"},{"name":"ojob report","help":{"text":"Outputs a jobs report (e.g. job name, status, number of executions, total time, avg time and last execution)","expects":[{"name":"__format","desc":"Can be json, yaml, table (default) or any other ow.oJob.output format"}]},"exec":"ow.loadFormat();print(\"\\n\");var b=$ch(\"oJob::log\").getAll(),c=$from(b).notEquals(\"name\",\"ojob report\").notEquals(\"name\",\"ojob final report\").select(function(a){return{\"Job name\":a.name,Status:a.start?a.success?\"OK\":a.deps?a.error?\"NOT OK!\":\"executing\":\"failed deps\":\"not started\",\"# execs\":a.count,\"Total time\":ow.format.elapsedTime4ms(a.totalTime,{abrev:!0}),\"Avg time\":ow.format.elapsedTime4ms(a.avgTime,{abrev:!0}),\"Last exec\":0<a.log.length?ow.format.timeago($from(a.log).sort(\"-endTime\").at(0).endTime):\n\"n/a\"}});c.push({\"Job name\":\"TOTAL:\",Status:\"\",\"# execs\":\"\",\"Total time\":ow.format.elapsedTime4ms(now()-$from(b).sort(\"createDate\").at(0).createDate),\"Avg time\":\"\",\"Last exec\":\"\"});args.__format=_$(args.__format).default(\"table\");ow.oJob.output(c,args)"},{"name":"ojob options","typeArgs":{"noLog":true,"shortcut":{"name":"optionOn","keyArg":"__optionOn","args":{"lowerCase":"__lowerCase","upperCase":"__upperCase","todos":"__todos","default":"__default","async":"__async"}}},"help":{"text":"Adds new \"todo\" entries depending on the value of a provided args variable.\n\nExample:\n\n __optionOn : mode\n __lowerCase: true\n __todos :\n mode1:\n - Job 1\n - Job 2\n mode2:\n - Job 2\n - Job 3\n __default:\n - Job 2\n","expects":[{"name":"__optionOn","desc":"The variable in args that will define which set of \"todo\"s will be added (trimmed)","required":true},{"name":"__lowerCase","desc":"Boolean value to determine if should compare the optionOn in lower case (defaults to false)"},{"name":"__upperCase","desc":"Boolean value to determine if should compare the optionOn in upper case (defaults to false)"},{"name":"__todos","desc":"Map where each option value should have a list/array of \"todo\"s","required":true},{"name":"__default","desc":"Default array of \"todo\"s"},{"name":"__async","desc":"Boolean value that if true, run the todos in async mode"}]},"check":{"in":{"__optionOn":"isString","__todos":"isMap","__lowerCase":"toBoolean.isBoolean.default(false)","__upperCase":"toBoolean.isBoolean.default(false)","__default":"default([])","__async":"toBoolean.isBoolean.default(false)"}},"exec":"isUnDef(args.__optionOn)&&isDef(args.optionOn)&&(args.__optionOn=args.optionOn);isUnDef(args.__todos)&&isDef(args.todos)&&(args.__todos=args.todos);isUnDef(args.__lowerCase)&&isDef(args.lowerCase)&&(args.__lowerCase=args.lowerCase);isUnDef(args.__upperCase)&&isDef(args.upperCase)&&(args.__upperCase=args.upperCase);isUnDef(args.__default)&&isDef(args.default)&&(args.__default=args.default);isString(args.__default)&&(args.__default=[args.__default]);var a=String(args[args.__optionOn]).trim();\nargs.__lowerCase&&(a=a.toLowerCase());args.__upperCase&&(a=a.toUpperCase());var b=clone(args);delete b.__default;delete b.__lowerCase;delete b.__upperCase;delete b.__todos;delete b.__optionOn;delete b.__async;isDef(args.__todos[a])&&isString(args.__todos[a])&&(args.__todos[a]=[args.__todos[a]]);a=isDef(args.__todos[a])&&isArray(args.__todos[a])?{todo:args.__todos[a]}:{todo:args.__default};a.todo.forEach(function(c){isString(c.args)&&(c.args=ow.oJob.__processArgs(c.args));isMap(c)?c.args=merge(c.args,\nb):c.args=b});args.__async?$job(\"ojob parallel\",merge(b,a)):$job(\"ojob todo\",merge(b,a))"},{"name":"ojob sec get","typeArgs":{"noLog":true,"shortcut":{"name":"secget","keyArg":"secKey","args":{"secRepo":"secRepo","secBucket":"secBucket","secPass":"secPass","secOut":"secOut","secMainPass":"secMainPass","secFile":"secFile","secDontAsk":"secDontAsk","secIgnore":"secIgnore","secEnv":"secEnv"}}},"help":{"text":"This job will get a SBucket secret and map it to oJob's args","expects":[{"name":"secIn","desc":"The args path where all the remaining sec arguments should be read from (defaults to no path)"},{"name":"[secIn].secOut","desc":"The args path to be mapped with the secret (defaults to secIn)"},{"name":"[secIn].secKey","desc":"The SBucket key"},{"name":"[secIn].secRepo","desc":"The SBucket repository"},{"name":"[secIn].secBucket","desc":"The SBucket name"},{"name":"[secIn].secPass","desc":"The SBucket password"},{"name":"[secIn].secMainPass","desc":"The SBucket repository password"},{"name":"[secIn].secFile","desc":"Optional provide a specific sbucket file"},{"name":"[secIn].secDontAsk","desc":"Determine if passwords should be asked from the user (default=false)"},{"name":"[secIn].secEnv","desc":"If true will set everything to retrieve the secret from an env variable"},{"name":"[secIn].secIgnore","desc":"If true will ignore errors of sec parameters not being provided (default=false)"}],"returns":[{"name":"[secIn].[secOut]","desc":"The args path to be mapped with the secret (defaults to secIn)"}]},"check":{"in":{"secIn":"isString.default(\"\")"}},"exec":"ow.loadSec();var a=args.secIn;\"\"!=a&&(a+=\".\");var f=_$($$(args).get(a+\"secIgnore\"),\"secIgnore\").isBoolean().default(!1),g=_$($$(args).get(a+\"secOut\"),\"secOut\").default(\"\"!=a?a.replace(/\\.$/,\"\"):__);f||_$($$(args).get(a+\"secKey\"),\"secKey\").$_();f=toBoolean(_$($$(args).get(a+\"secDontAsk\"),\"secDontAsk\").default(!1));var h=_$($$(args).get(a+\"secKey\"),\"secKey\").default(__),b=_$($$(args).get(a+\"secBucket\"),\"secBucket\").default(__),c=_$($$(args).get(a+\"secPass\"),\"secPass\").default(__),l=_$($$(args).get(a+\n\"secFile\"),\"secFile\").default(__),k=_$($$(args).get(a+\"secRepo\"),\"secRepo\").default(__),d=_$($$(args).get(a+\"secMainPass\"),\"secMainPass\").default(__);_$(toBoolean($$(args).get(a+\"secEnv\")),\"secEnv\").isBoolean().default(!1)&&(k=\"system\",b=\"envs\",f=!0);!f&&isDef(h)&&(b=askDef(b,\"Sec bucket: \"),isDef(b)&&isUnDef(l)&&(c=askDef(c,\"Sec bucket '\"+b+\"' pass: \",!0)),isDef(k)&&(d=askDef(d,\"Sec repo '\"+k+\"' pass: \",!0)));isUnDef(c)&&isDef(args.secPass)&&(c=args.secPass);isUnDef(d)&&isDef(args.secMainPass)&&\n(d=args.secMainPass);if(isDef(h)){var e=$sec(k,b,c,d,l).get(h);if(isUnDef(e))throw\"Couldn't retrieve secKey '\"+h+\"' from bucket '\"+b+\"'!\";isDef(g)&&0<g.length?(a=$$(args).get(g),$$(args).set(g,isDef(a)?merge(a,e):e)):Object.keys(e).forEach(function(m){return $$(args).set(m,e[m])})}"},{"name":"ojob split to items","help":{"text":"Splits an args source into an array of maps (_list).\n\nExample:\n\n a source string with the value \"abc, xyz, 1\"\n + separator = ','\n transforms into:\n\n - item: abc\n - item: xyz\n - item: 1\n","expects":[{"name":"source","desc":"A object path to the string source to split"},{"name":"separator","desc":"The separator for the source string (defaults to \\n)"}]},"exec":"_$(args.source,\"source\").isString().$_();args.separator=_$(args.separator,\"separator\").isString().default(\"\\n\");ow.loadObj();args._list=String(ow.obj.getPath(args,args.source)).split(args.separator).map(function(a){return{item:a}})"},{"name":"ojob query","typeArgs":{"noLog":true,"shortcut":{"name":"query","keyArg":"__query","args":{"type":"__type","from":"__from","to":"__to","toKey":"__toKey","key":"__key"}}},"help":{"text":"Performs a query (using ow.obj.filter) to the existing args.","expects":[{"name":"__query","desc":"The query map for ow.obj.filter or af.fromNLinq"},{"name":"__type","desc":"The type of query to perform (e.g. path, sql or nlinq)"},{"name":"__from","desc":"The path to the args key to perform the query"},{"name":"__to","desc":"The path to where the results should be stored in args"},{"name":"__toKey","desc":"If __to not provided defaults to $set on the provided key"},{"name":"__key","desc":"If __from and/or __to not provided defaults to $get/$set on the provided key"}]},"exec":"isUnDef(args.__from)&&isDef(args.from)&&(args.__from=args.from);isUnDef(args.__key)&&isDef(args.key)&&(args.__key=args.key);isUnDef(args.__query)&&(args.__query={});isUnDef(args.__key)&&(args.__key=\"res\");var a=\"args\"==args.__key?args:$get(args.__key);isDef(args.__from)&&(a=$path(a,args.__from));ow.loadObj();switch(args.__type){case \"path\":a=$path(a,args.__query);break;case \"sql\":a=$sql(a,args.__query);break;default:a=isString(args.__query)?$from(a).query(af.fromNLinq(args.__query)):$from(a).query(args.__query)}\"args\"==\nargs.__key&&isUnDef(args.__toKey)?$$(args).set(isDef(args.__to)?args.__to:args.__from,a):isDef(args.__toKey)?$set(args.__toKey,a):$set(args.__key,a);Object.keys(args).filter(function(b){return b.startsWith(\"__\")}).forEach(function(b){return delete args[b]})"},{"name":"ojob set envs","help":{"text":"Sets job args based on environment variables.","expects":[{"name":"envs","desc":"A map where each key corresponds to an environment variable and the value to the args path where it should be placed"}]},"check":{"in":{"envs":"isMap"}},"exec":"Object.keys(args.envs).forEach(function(a){var b=args.envs[a];a=getEnv(a);isDef(a)&&!isNull(a)&&$$(args).set(String(b),String(a))})"},{"name":"ojob if","typeArgs":{"noLog":true,"shortcut":{"name":"if","keyArg":"__condition","args":{"then":"__then","else":"__else","debug":"__debug"}}},"help":{"text":"If the provided \"condition\" is evaluated as true it will execute the \"then\" jobs otherwise it will execute the \"else\" jobs","expects":[{"name":"__condition","desc":"An OpenAF code condition with templating functionality (example: \"{{abc}} == 123\")"},{"name":"__then","desc":"One job or a list of jobs to execute if the \"condition\" is true"},{"name":"__else","desc":"One job or a list of jobs to execute if the \"condition\" is false"},{"name":"__debug","desc":"Boolean to indicate if should log the original condition and the parsed condition for debug proposes"}]},"check":{"in":{"__condition":"isString","__then":"default([])","__else":"default([])","__debug":"toBoolean.isBoolean.default(false)"}},"exec":"isString(args.__then)&&(args.__then=[args.__then]);isString(args.__else)&&(args.__else=[args.__else]);var a=String(args.__condition);delete args.__condition;var e=clone(args.__then);delete args.__then;var f=clone(args.__else);delete args.__else;var d=!!args.__debug;delete args.__debug;var b=templify(a,args).replace(/\\n/g,\"\");d&&log(\" DEBUG | \"+af.toSLON({origCondition:\" \"+a+\" \",parsedCondition:\" \"+b+\" \"}));b=af.eval(b);d&&log(\" DEBUG | \"+af.toSLON({origCondition:\" \"+a+\" \",result:b}));\na=function(c){c=ow.oJob.parseTodo(c);$job(c,args)};b?e.forEach(a):f.forEach(a)"},{"name":"ojob repeat","typeArgs":{"noLog":true,"shortcut":{"name":"repeat","keyArg":"__time","args":{"todo":"__jobs"}}},"help":{"text":"Repeats sequentially, for a specific number of \"times\", the provided list of \"jobs\" (one or more)","expects":[{"name":"__times","desc":"The number of times to repeat the provided list of jobs"},{"name":"__jobs","desc":"One job or a list of jobs to execute each time"}]},"check":{"in":{"__times":"toNumber.isNumber"}},"exec":"if(!isString(args.__jobs)&&!isArray(args.__jobs))throw\"The provided 'jobs' need to be one or a list of jobs.\";if(isUnDef(args.__jobs))throw\"No 'jobs' list was provided.\";isString(args.__jobs)&&(args.__jobs=[args.__jobs]);var c=clone(args.__jobs);delete args.__jobs;var d=Number(args.__times);delete args.__times;var a=clone(args);delete a.__jobs;delete a.__time;for(var b=0;b<d;b++)$job(\"ojob todo\",merge(a,{todo:c}))"},{"name":"ojob repeat with each","typeArgs":{"noLog":true,"shortcut":{"name":"each","keyArg":"__path","args":{"key":"__key","todo":"__jbos"}}},"help":{"text":"Repeats the configured \"jobs\" (one or more jobs) sequentially for each element of the provided \"key\" list.","expects":[{"name":"__key","desc":"The key for an existing list or args"},{"name":"__path","desc":"The path to consider from __key"},{"name":"__jobs","desc":"One job or a list of jobs to execute each time"}]},"check":{"in":{"__key":"isString","__path":"isString.default(\"@\")"}},"exec":"if(!isString(args.__jobs)&&!isArray(args.__jobs))throw\"The provided 'jobs' need to be one or a list of jobs.\";if(isUnDef(args.__jobs))throw\"No 'jobs' list was provided.\";var b=String(args.__key),a=String(args.__path);delete args.__key;delete args.__path;isString(args.__jobs)&&(args.__jobs=[args.__jobs]);var d=clone(args.__jobs);delete args.__jobs;a=\"args\"==b?$path(args,a):$path($get(b),a);if(!isArray(a))throw\"The key/path '\"+b+\"' is not an array/list.\";a.forEach(function(e){d.forEach(function(c){c=\now.oJob.parseTodo(c);$job(c,merge(args,e))})})"},{"name":"ojob check","typeArgs":{"noLog":true,"shortcut":{"name":"check","keyArg":"_checks","args":{"actions":"_actions"}}},"to":"ojob job"},{"name":"ojob job","typeArgs":{"noLog":true},"help":{"text":"Provides a way to organize idempotent jobs. One or more \"checks\" jobs will be called to determine an args._action.\nInitially the args._action is set to \"none\". If the \"checks\" jobs determine an action it will call the corresponding\njobs on \"actions\" jobs. If \"_go=true\" is not provided, instead of running, it will only return a plan of actions. \nFor example:\n\n - name: Write Hello World\n to : ojob job\n args:\n _checks : Check Hello World\n _actions:\n create : Create Hello World\n overwrite: Overwrite Hello World\n delete : Delete Hello World\n","expects":[{"name":"_checks","desc":"A list of one or more jobs to be called to perform checks to determine an args._action"},{"name":"_actions","desc":"A map of possible values of args._action whose values are one or more jobs to execute"},{"name":"_go","desc":"A boolean value (defaults to false) that controls if the _actions jobs are called (when true) or not"}]},"check":{"in":{"_go":"toBoolean.isBoolean.default(false)"}},"exec":"isString(args._checks)&&(args._checks=[args._checks]);isString(args._actions)&&(args._actions={none:args._actions});var c=function(a){a=clone(a);delete a._checks;delete a._actions;return a};args._action=\"none\";args._checks.forEach(function(a){isString(a)?(a=$job(a,c(args)),isMap(a)&&isString(a._action)&&(args._action=a._action)):logErr(\"oJob Job 'checks' must be job names\")});$ch(\"_ojob_plan\").create();$ch(\"_ojob_plan\").get({name:job.name});var d=[];if(isDef(args._actions[args._action])){var b;\nisArray(args._actions[args._action])&&(b=args._actions[args._action]);isString(args._actions[args._action])&&(b=[args._actions[args._action]]);b.forEach(function(a){args._go?$job(a,c(args)):d.push(a)})}$ch(\"_ojob_plan\").set({name:job.name},{name:job.name,action:args._action,\"go?\":args._go,plan:d})"},{"name":"ojob job report","help":{"text":"Outputs a job jobs report (e.g. job name, action and plan)","expects":[{"name":"__format","desc":"Can be json, yaml, table (default) or any other ow.oJob.output format"}]},"exec":"ow.oJob.output($ch(\"_ojob_plan\").getAll(),{__format:_$(args.__format).default(\"table\")})"},{"name":"ojob job final report","type":"shutdown","to":"ojob job report","help":{"text":"Outputs a job jobs report (e.g. job name, action and plan) upon ojob termination","expects":[{"name":"__format","desc":"Can be json, yaml, table (default) or any other ow.oJob.output format"}]}},{"name":"ojob set state","typeArgs":{"noLog":true,"shortcut":{"name":"state","keyArg":"__state"}},"help":{"text":"Changes the current state.","expects":[{"name":"__state","desc":"The state to change to (to execute todo.when)"}]},"exec":"isUnDef(args.__state)&&isDef(args.state)&&(args.__state=args.state);_$(args.__state,\"state\").isString().$_();ow.oJob.setState(args.__state)"},{"name":"ojob get state","help":{"text":"Gets the current state into args.state.","returns":[{"name":"state","desc":"The current state"}]},"exec":"args.state=ow.oJob.getState()"},{"name":"ojob state","typeArgs":{"noLog":true},"help":{"text":"Changes the current state depending on the value of a provided args variable.\n\n Example:\n\n stateOn : mode\n lowerCase: true\n default : Help\n","expects":[{"name":"stateOn","desc":"The variable in args that will define the current global set (to execute todo.when)"},{"name":"lowerCase","desc":"A boolean value to determine if should compare the stateOn in lower case (defaults to false)"},{"name":"upperCase","desc":"A boolean value to determine if should compare the stateOn in upper case (defaults to false)"},{"name":"validStates","desc":"An array of valid states to change to. If not included the default will be choosen (or none)."},{"name":"default","desc":"Default value of state"}]},"check":{"in":{"stateOn":"isString.default(\"state\")","lowerCase":"toBoolean.isBoolean.default(false)","upperCase":"toBoolean.isBoolean.default(false)","default":"default(__)"}},"exec":"args.state=_$(args[args.stateOn],args.stateOn).default(args.default);args.lowerCase&&isString(args.state)&&(args.state=args.state.toLowerCase());args.upperCase&&isString(args.state)&&(args.state=args.state.toUpperCase());isArray(args.validStates)&&0>args.validStates.indexOf(args.state)&&(isDef(args.default)?args.state=args.default:args.state=__);isString(args.state)&&isDef(ow.oJob.setState)&&ow.oJob.setState(args.state)"},{"name":"ojob todo","typeArgs":{"noLog":true,"shortcut":{"name":"todo","keyArg":"todo","args":{"isolateArgs":"isolateArgs","isolateJob":"isolateJob","templateArgs":"templateArgs","shareArgs":"shareArgs","debug":"__debug"}}},"help":{"text":"Executes an ojob sub-todo.\nNOTE: doesn't perform any checks for recursive behaviour!","expects":[{"name":"todo","desc":"A string or array of todo' maps"},{"name":"todo[].name","desc":"Name of the job to execute"},{"name":"todo[].args","desc":"Arguments to merge (if isolateArgs is not true) with the main job arguments"},{"name":"todo[].isolateArgs","desc":"Boolean to indicate, for a specific todo, that args should be isolated from all others"},{"name":"todo[].isolateJob","desc":"Boolean to indicate, for a specific todo, that the job should run in a different scope (e.g. deps will not work)"},{"name":"todo[].templateArgs","desc":"Boolean to indicate, for a specific todo, to apply template to each string of the provided args (use only if typeArgs.noTemplateArgs = false OR job.templateArgs = true)"},{"name":"isolateArgs","desc":"Boolean, false by default, to indicate that args should be isolated from all others"},{"name":"isolateJob","desc":"Boolean, false by default, to indicate that the job should run in a different scope (e.g. deps will not work)"},{"name":"templateArgs","desc":"Boolean, true by default, to indicate to apply template to each string of the provided args (use only if typeArgs.noTemplateArgs = false OR job.templateArgs = true)"},{"name":"shareArgs","desc":"Boolean, false by default, to indicate that args should be shared between all todo's jobs sequentially."},{"name":"__debug","desc":"Boolean to indicate that each job execution parameters should be printed before executing"}]},"check":{"in":{"isolateArgs":"toBoolean.isBoolean.default(false)","isolateJob":"toBoolean.isBoolean.default(false)","templateArgs":"toBoolean.isBoolean.default(true)","shareArgs":"toBoolean.isBoolean.default(false)","__debug":"toBoolean.isBoolean.default(false)"}},"exec":"if(!isString(args.todo)&&!isArray(args.todo))throw\"todo needs to be a string or an array\";isString(args.todo)&&(args.todo=[args.todo]);var a=clone(args);delete a.todo;delete a.isolateArgs;delete a.templateArgs;delete a.shareArgs;delete a.__debug;args.todo.forEach(function(b){if(!isMap(b)&&!isString(b))throw\"todo entry needs to be a map or a string (\"+af.toSLON(b)+\")\";b=$job(\"ojob run\",{job:b,id:ow.oJob.__id,isolateArgs:args.isolateArgs,isolateJob:args.isolateJob,templateArgs:args.templateArgs,\n__debug:args.__debug,args:a});args.shareArgs&&(a=merge(a,b))})"},{"name":"ojob run","typeArgs":{"noLog":true},"check":{"in":{"job":"default(__)","id":"isString.default(ow.oJob.__id)","isolateArgs":"toBoolean.isBoolean.default(false)","isolateJob":"toBoolean.isBoolean.default(false)","templateArgs":"toBoolean.isBoolean.default(true)","__debug":"toBoolean.isBoolean.default(false)"}},"help":{"text":"Executes an ojob but alternatively use 'ojob todo' or $job for most functionality.","expects":[{"name":"job","desc":"Name of the job to execute"},{"name":"id","desc":"The oJob id to execute (leave undefined to default to the current one)"},{"name":"args","desc":"The args to consider on execution."},{"name":"isolateArgs","desc":"Boolean to indicate that args should be isolated."},{"name":"isolateJob","desc":"Boolean to indicate that the job should run in a different scope (e.g. deps will not work)"},{"name":"templateArgs","desc":"Boolean to indicate to apply template to each string of the provided args (use only if typeArgs.noTemplateArgs = false OR job.templateArgs = true)"},{"name":"__debug","desc":"Boolean to indicate that each job execution parameters should be printed before executing"}]},"exec":"if(!isString(args.job)&&!isMap(args.job))throw\"job needs to be either a string or job map\";isString(args.job)&&(args.job={name:args.job});args.job.templateArgs=_$(args.job.templateArgs,\"templateArgs \"+args.job.name).isBoolean().default(args.templateArgs);args.job.isolateArgs=_$(args.job.isolateArgs,\"isolateArgs \"+args.job.name).isBoolean().default(args.isolateArgs);args.job.isolateJob=_$(args.job.isolateJob,\"isolateJob \"+args.job.name).isBoolean().default(args.isolateJob);args.job.templateArgs&&\nisDef(args.args)&&args.job.templateArgs&&isDef(args.job.args)&&(isString(args.job.args)&&(args.job.args=ow.oJob.__processArgs(args.job.args)),traverse(args.job.args,function(c,b,e,d){isString(b)&&(d[c]=templify(b,args))}));args.job=ow.oJob.parseTodo(args.job);var a={name:args.job.name,args:args.job.isolateArgs?args.job.args:merge(args.args,args.job.args),id:args.job.isolateJob?__:args.id};args.__debug&&cprint(ow.format.withSideLine(printTreeOrS(a,__,{bgcolor:\"BG(235)\"}),__,\"FG(240)\",\"BG(235)\",ow.format.withSideLineThemes().openBottomCurvedRect));\nargs=merge(args,$job(a.name,a.args,a.id))"},{"name":"ojob run file","typeArgs":{"noLog":true,"shortcut":{"name":"runfile","keyArg":"__job","args":{"args":"__args","out":"__out","key":"__key","inKey":"__inKey","usePM":"__usePM","inPM":"__inPM","templateArgs":"__templateArgs","debug":"__debug"}}},"help":{"text":"Executes an external YAML/JSON ojob file or a remote URL with the provided args.","expects":[{"name":"__job","desc":"The YAML/JSON ojob file or remote URL to run"},{"name":"__args","desc":"The args to provide to the external ojob file/url"},{"name":"__out","desc":"The path on args to set the map key/path contents"},{"name":"__key","desc":"If __out is not defined will set the content into the provided key"},{"name":"__inKey","desc":"If defined, args will be merged with the content from the provided key"},{"name":"__usePM","desc":"Output to __pm"},{"name":"__inPM","desc":"Input from provided key to __pm"},{"name":"__templateArgs","desc":"Boolean to indicate to apply template to each string of the provided args (use only if typeArgs.noTemplateArgs = false OR job.templateArgs = true)"},{"name":"__debug","desc":"Boolean to indicate that the job execution parameters should be printed before executing"}]},"check":{"in":{"__job":"isString","__args":"isMap.default({})","__out":"isString.default(__)","__key":"isString.default(\"res\")","__inKey":"isString.default(__)","__usePM":"toBoolean.isBoolean.default(false)","__inPM":"isString.default(__)","__templateArgs":"toBoolean.isBoolean.default(false)","__debug":"toBoolean.isBoolean.default(false)"}},"exec":"var c=\"args\"==args.__key?\"r\"+nowNano():args.__key;args.__templateArgs&&isDef(args.__args)&&traverse(args.__args,function(b,d,g,f){isString(d)&&(f[b]=templify(d,args))});if(args.__usePM){var a={__format:\"pm\"};args.__key=__;args.__usePM=__}else a={__format:\"key\",__key:c};if(isDef(args.__inKey)){var e=$get(args.__inKey);a=merge(isDef(e)?merge(args.__args,e):args.__args,a)}else a=merge(args.__args,a);isDef(args.__inPM)&&ow.oJob.output($get(args.__inPM),{__format:\"pm\"});args.__debug&&cprint(ow.format.withSideLine(printTreeOrS(a,\n__,{bgcolor:\"BG(235)\"}),__,\"FG(235)\",\"BG(235)\",ow.format.withSideLineThemes().openBottomCurvedRect));oJobRunFile(args.__job,a,nowNano(),{shareArgs:!1},!0);if(\"args\"==args.__key||\"res\"==args.__key)a=$get(c),isDef(a)&&(delete a.__format,delete a.__key,args=merge(args,a),\"args\"==args.__key&&$unset(c));Object.keys(args).filter(function(b){return b.startsWith(\"__\")}).forEach(function(b){return delete args[b]})"},{"name":"ojob parallel","typeArgs":{"noLog":true,"shortcut":{"name":"parallel","keyArg":"todo"}},"help":{"text":"Executes an ojob sub-todo in parallel.\nNOTE: doesn't perform any checks for recursive behaviour!","expects":[{"name":"todo","desc":"A string or array of todo' maps"},{"name":"todo[].name","desc":"Name of the job to execute"},{"name":"todo[].args","desc":"Arguments to merge (if isolateArgs is not true) with the main job arguments"},{"name":"todo[].isolateArgs","desc":"Boolean to indicate, for a specific todo, that args should be isolated from all others"},{"name":"todo[].isolateJob","desc":"Boolean to indicate, for a specific todo, that the job should run in a different scope (e.g. deps will not work)"},{"name":"todo[].templateArgs","desc":"Boolean to indicate, for a specific todo, to apply template to each string of the provided args (use only if typeArgs.noTemplateArgs = false OR job.templateArgs = true)"},{"name":"isolateArgs","desc":"Boolean, false by default, to indicate that args should be isolated from all others"},{"name":"isolateJob","desc":"Boolean, false by default, to indicate that the job should run in a different scope (e.g. deps will not work)"},{"name":"templateArgs","desc":"Boolean, true by default, to indicate to apply template to each string of the provided args (use only if typeArgs.noTemplateArgs = false OR job.templateArgs = true)"},{"name":"shareArgs","desc":"Boolean, false by default, to indicate that args should be shared between all todo's jobs sequentially."},{"name":"__debug","desc":"Boolean to indicate that each job execution parameters should be printed before executing"}]},"check":{"in":{"isolateArgs":"toBoolean.isBoolean.default(false)","isolateJob":"toBoolean.isBoolean.default(false)","templateArgs":"toBoolean.isBoolean.default(true)","shareArgs":"toBoolean.isBoolean.default(false)","__debug":"toBoolean.isBoolean.default(false)"}},"exec":"if(!isString(args.todo)&&!isArray(args.todo))throw\"todo needs to be a string or an array\";isString(args.todo)&&(args.todo=[args.todo]);var a=clone(args),c=[];delete a.todo;delete a.isolateArgs;delete a.templateArgs;delete a.shareArgs;delete a.__debug;args.todo.forEach(function(b){if(!isMap(b)&&!isString(b))throw\"todo entry needs to be a map or a string (\"+af.toSLON(b)+\")\";c.push($do(function(){return $job(\"ojob run\",{job:b,id:ow.oJob.__id,isolateArgs:args.isolateArgs,isolateJob:args.isolateJob,\ntemplateArgs:args.templateArgs,__debug:args.__debug,args:a})}))});$doWait($doAll(c))"},{"name":"ojob wait","typeArgs":{"noLog":true,"shortcut":{"name":"wait","keyArg":"time"}},"help":{"text":"Waits for a specific amount of time","expects":[{"name":"time","desc":"The amount of time, in ms, to pause execution"}]},"check":{"in":{"time":"toNumber.isNumber"}},"exec":"sleep(args.time,!0)"},{"name":"ojob exit","typeArgs":{"noLog":true,"shortcut":{"name":"fail","keyArg":"code","args":{"force":"force"}}},"help":{"text":"Ends all processing with an exit code","expects":[{"name":"code","desc":"The exit code number to use"},{"name":"force","desc":"A boolean indicating if instead of exit the processing should halt"}]},"check":{"in":{"code":"toNumber.isNumber.default(0)","force":"toBoolean.isBoolean.default(false)"}},"exec":"exit(args.code,args.force)"},{"name":"ojob convert","typeArgs":{"noLog":false,"shortcut":{"name":"convert","keyArg":"__inKey","args":{"inPath":"__inPath","inFormat":"__inFormat","outPath":"__outPath","outKey":"__outKey"}}},"check":{"in":{"__inPath":"isString.default(\"\")","__inKey":"isString.default(\"res\")","__inFormat":"isString.oneOf(['yaml','json','xml','ndjson','slon'])","__outPath":"isString.default(__)","__outKey":"isString.default(__)"}},"help":{"text":"Converts string content into an internal object (map/array)","expects":[{"name":"__inKey","desc":"Where to find the input contents to convert (if 'args' will default to the current args)"},{"name":"__inPath","desc":"The path on the input contents for the string to convert"},{"name":"__inFormat","desc":"The format of the input contents (yaml, json, xml, ndjson, slon)"},{"name":"__outKey","desc":"Where the converted output object should be placed (if 'args' with default to the current args)"},{"name":"__outPath","desc":"The path on the output contents to store the converted object"}]},"exec":"var c=\"args\"!=args.__inKey?String($$(args).get(args.__inPath)):String($$($get(args.__inKey)).get(args.__inPath));isUnDef(args.__outKey)&&(args.__outKey=args.__inKey);isUnDef(args.__outPath)&&(args.__outPath=args.__inPath);switch(args.__inFormat){case \"yaml\":_$(c,\"yaml input\").isString().$_();var a=af.fromYAML(c);break;case \"json\":a=jsonParse(c,!0);break;case \"ndjson\":a=c.split(\"\\n\").map(function(b){return jsonParse(b,!0)}).filter(function(b){return isDef(b)&&!isNull(b)});break;case \"xml\":a=\naf.fromXML2Obj(a);break;case \"slon\":a=af.fromSLON(a);break;default:throw\"No inFormat provided.\";}\"args\"!=args.__outKey?$$(args).set(args.__outPath,a):($get(args.outKey),$$(o).set(args.outPath,a),$set(args.outKey,o));Object.keys(args).filter(function(b){return b.startsWith(\"__\")}).forEach(function(b){return delete args[b]})"},{"name":"ojob questions","typeArgs":{"noLog":true,"shortcut":{"name":"questions","keyArg":"__questions"}},"help":{"text":"Asks a list of questions and stores the answers into args.\n","expects":[{"name":"__questions","desc":"A map structure equivalent to OpenAF's askStruct."}]},"check":{"in":{"__questions":"isArray"}},"exec":"askStruct(args.__questions).forEach(function(a){isDef(a.name)&&$$(args).set(a.name,a.answer)})"},{"name":"ojob ask","typeArgs":{"noLog":true,"shortcut":{"name":"ask","keyArg":"__answers","args":{"question":"__question","force":"__force"}}},"help":{"text":"Asks for user input and stores the result into args if the args value is not yet defined.\n","expects":[{"name":"__question","desc":"The question to ask."},{"name":"__answers","desc":"A map of answers to store into args. Each value should on the form of \"type.slonOptionsArray.size\" (e.g. text, encrypt, password, char.['y'|'n'], option.['op1'|'op2'|'op3'].3, moption.['op1'|'op2'|'op3'].3)"},{"name":"__force","desc":"Boolean flag to force asking for an args value even if not defined."}]},"check":{"in":{"__question":"isString.default(__)","__answers":"isMap.default({})","__force":"toBoolean.isBoolean.default(false)"}},"exec":"isDef(args.__question)&&(args.__question=args.__question.replace(/\\n/g,\"\"),args.__question.endsWith(\" \")||(args.__question+=\" \"));traverse(args.__answers,function(c,b,d,e){if(isString(b)&&(args.__force||isUnDef($$(args).get(d+\".\"+c)))){b=b.split(\".\");var a=_$(a,\"options\").isArray().default([]);isDef(b[1])&&b[1].startsWith(\"[\")&&b[1].endsWith(\"]\")&&(a=af.fromSLON(b[1]));isArray(a)||(a=[a]);if(isString(b[0]))switch(isUnDef(args.__question)&&(args.__question=\"args\"+d+\".\"+c+\" value: \"),b[0].toLowerCase()){case \"encrypt\":case \"password\":$$(args).set(d+\n\".\"+c,askEncrypt(args.__question));break;case \"char\":a=a.join(\"\");$$(args).set(d+\".\"+c,ask1(args.__question),a);break;case \"option\":case \"list\":if(isArray(a)){$$(args).set(d+\".\"+c,a[askChoose(args.__question,a,isDef(b[2])?Number(b[2]):__)]);break}case \"moption\":if(isArray(a)){$$(args).set(d+\".\"+c,a[askChooseMultiple(args.__question,a,isDef(b[2])?Number(b[2]):__)]);break}default:$$(args).set(d+\".\"+c,ask(args.__question))}}})"},{"name":"ojob oafp","typeArgs":{"noLog":true,"shortcut":{"name":"oafp","keyArg":"__params"},"help":{"text":"\"Executes oafp with the provided params\"\n","expects":[{"name":"__params","desc":"The parameters to provide to oafp"}]}},"check":{"in":{"__params":"isMap"}},"exec":"loadOAFP();oafp(args.__params)"},{"name":"ojob llm","typeArgs":{"noLog":true,"shortcut":{"name":"llm","keyArg":"__llmPrompt","args":{"context":"__llmContext","inPath":"__llmInPath","inKey":"__llmInKey","env":"__llmEnv","options":"__llmOptions","outPath":"__llmOutPath","debug":"__llmDebug"}}},"help":{"text":"\"Executes a LLM (Local Language Model) prompt using $llm\"\n","expects":[{"name":"__llmContext","desc":"The context of the input data (determined by __llmInPath)"},{"name":"__llmInPath","desc":"The path to consider from __llmInKey (mandatory for using context)"},{"name":"__llmInKey","desc":"The key for an existing list or 'args'"},{"name":"__llmEnv","desc":"The environment variable to consider for $llm options"},{"name":"__llmOptions","desc":"The options to consider for $llm"},{"name":"__llmOutPath","desc":"The path to store the result"},{"name":"__llmPrompt","desc":"The prompt to send to the LLM model"},{"name":"__llmDebug","desc":"Boolean to indicate that the job execution parameters should be printed before executing"}]},"check":{"in":{"__llmContext":"isString.default(__)","__llmInKey":"isString.default(\"args\")","__llmInPath":"isString.default(__)","__llmEnv":"isString.default(\"OJOB_MODEL\")","__llmOptions":"isMap.default(__)","__llmOutPath":"isString.default(__)","__llmPrompt":"isString","__llmDebug":"isBoolean.default(false)"}},"exec":"try{var a=isDef(args.__llmOptions)?args.__llmOptions:__;isUnDef(a)&&isDef(args.__llmEnv)&&(a=$sec(\"system\",\"envs\").get(args.__llmEnv));var b=$llm(a);if(isDef(args.__llmInPath)){isUnDef(args.__llmContext)&&(args.__llmContext=\"a JSON input data\");var c=\"args\"==args.__llmInKey?$$(args).get(args.__llmInPath):$$($get(args.__llmInKey)).get(args.__llmInPath);args.__llmDebug&&(print(\"DEBUG | Input data:\"),cprint(c));isDef(c)&&(b=b.withContext(c,args.__llmContext))}var d=b.promptJSON(args.__llmPrompt);\nargs.__llmDebug&&(print(\"DEBUG | Result data:\"),cprint(d));isUnDef(args.__llmOutPath)?$set(\"res\",d):$$(args).set(args.__llmOutPath,d)}catch(e){throw\"Error on LLM: \"+e;}"}]}