Skip to content

Commit

Permalink
Add support for listing and searching examples
Browse files Browse the repository at this point in the history
  • Loading branch information
nmaguiar committed Apr 6, 2024
1 parent dfa966e commit c11982b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/docs/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Takes an input, usually a data structure such as json, and transforms it to an e
| urldata | If 'url' is provided a JSON/SLON/text data can be provided |
| loop | If defined will loop the processing by the number of seconds provided |
| loopcls | If 'true' and loop is defined it will clear the screen (or file) on each loop cycle |
| -examples | Will access an internet based list of oafp examples and list them |
| examples | Will search the provided keywork in the internet basd list of oafp examples |
| -v | Changes the input to a map with the tool's version info |
| version | Alternative way to change the input to a map with the tool's version |

Expand Down
22 changes: 21 additions & 1 deletion src/oafp.source.js.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,26 @@ if (params["-v"] == "" || (isString(params.version) && params.version.length > 0
showVersion()
}

// Check list of examples
if (params["-examples"] == "" || (isString(params.examples) && params.examples.length > 0)) {
params.url = "https://ojob.io/oafp-examples.yaml"
params.in = "yaml"

if (isString(params.examples) && params.examples.length > 0) {
options.__format = "template"
options.__path = "data"
params.templatepath = "tmpl"
options.__sql = "select * where d like '%" + params.examples + "%'"
} else {
options.__path = "data[].{category:c,subCategory:s,description:d}"
options.__from = "sort(category,subCategory,description)"
options.__format = "ctable"
}

delete params["-examples"]
delete params.file
}

// Read input from stdin or file
var _res = "", noFurtherOutput = false

Expand Down Expand Up @@ -476,7 +496,7 @@ var _run = () => {
// Verify debug
if (isDef(params["-debug"])) {
//__initializeCon()
printErr("DEBUG: " + stringify(params, __, __))
printErr("DEBUG: " + colorify(params))
}

if (isNumber(params.loop)) {
Expand Down

0 comments on commit c11982b

Please sign in to comment.