Skip to content

Commit 8587825

Browse files
author
ldn-softdev
committed
updated usage guideline & examples (-g)
1 parent c1f47d5 commit 8587825

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

lib/jtc_guide.hpp

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ void GuideJtc::print(void) {
4848
{"%c", STR(OPT_CMP) }, {"%s", STR(OPT_SWP) }, {"%l", STR(OPT_LBL) },
4949
{"%i", STR(OPT_INS) }, {"%u", STR(OPT_UPD) }, {"%p", STR(OPT_PRG) },
5050
{"%e", STR(OPT_EXE) }, {"%m", STR(OPT_MDF) }, {"%x", STR(OPT_CMN) },
51-
{"%y", STR(OPT_PRT) }, {"%T", STR(OPT_TMP) }, {"%f", STR(OPT_FRC) }
51+
{"%y", STR(OPT_PRT) }, {"%T", STR(OPT_TMP) }, {"%f", STR(OPT_FRC) },
52+
{"%a", STR(OPT_ALL)}
5253
};
5354
auto replace = [] (const replace_token &rt) {
5455
GuideJtc::jtc_usage_ = std::regex_replace(GuideJtc::jtc_usage_,
@@ -154,7 +155,7 @@ options -%x and -%y usage:
154155
JSON is a string, then outer quotation marks are dropped, if it's a JSON array or object, then
155156
the respective encasements ('[', ']', or '{', '}') are dropped, so the user must specify those
156157
- if an empty token is given (e.g.: {}, {{}}), then the interpolation of the currently selected
157-
(walked) JSON element occurs (thw same interpolation rules apply)
158+
(walked) JSON element occurs (the same interpolation rules apply)
158159
159160
operations chaining:
160161
- jtc normally performs one (primary) operation at a time; if multiple required those could be
@@ -166,6 +167,15 @@ operations chaining:
166167
here, all operations are performed by a single jtc invocation, resulting in a much faster
167168
performance, plus that way the namespace is common across all the steps, which allows achieving
168169
operations with JSON otherwise unattainable in the former notation
170+
171+
single/multiple JSONs and sources:
172+
- if a single JSON source is given (file, or <std-in>), then jtc will process only the first JSON
173+
and then quit. If the single source holds multiple JSONs and all to be processed, then option
174+
-%a is required.
175+
- if multiple sources given (i.e., multiple files) then option -%a is assumed and is not required,
176+
jtc then performs reading and parsing from multiple files concurrently (in multiple threads).
177+
However, if option -%a is given, then it disables concurrent JSON reading/parsing and forces
178+
processing of all the input files sequentially (in a single thread)
169179
)"};
170180

171181

@@ -255,7 +265,7 @@ std::string GuideJtc::jtc_examples_{R"(
255265
"Relation": [
256266
{
257267
"age": 31,
258-
"children": [ "Sophia", "Olivia", "James", "James" ],
268+
"children": [ "Sophia", "Olivia", "James" ],
259269
"city": "New York",
260270
"parent": "John Smith"
261271
},
@@ -276,7 +286,7 @@ std::string GuideJtc::jtc_examples_{R"(
276286
"Relation": [
277287
{
278288
"age": 31,
279-
"children": [ "Sophia", "Olivia", "James", "James" ],
289+
"children": [ "Sophia", "Olivia", "James" ],
280290
"city": "New York",
281291
"parent": "Jane Smith"
282292
},
@@ -291,12 +301,12 @@ std::string GuideJtc::jtc_examples_{R"(
291301
292302
293303
- to add a new record into a JSON node where parent is '"Jane Smith"':
294-
jtc -tc -%w'[parent]:<Jane Smith>[-1]' -%i'{"gene": "Y"}' example.json
304+
jtc -tc -w'[parent]:<Jane Smith>[-1]' -i'{"gene": "Y"}' example.json
295305
{
296306
"Relation": [
297307
{
298308
"age": 31,
299-
"children": [ "Sophia", "Olivia", "James", "James" ],
309+
"children": [ "Sophia", "Olivia", "James" ],
300310
"city": "New York",
301311
"gene": "Y",
302312
"parent": "Jane Smith"
@@ -319,7 +329,7 @@ std::string GuideJtc::jtc_examples_{R"(
319329
"Relation": [
320330
{
321331
"age": 31,
322-
"children": [ "Sophia", "Olivia", "James", "James" ],
332+
"children": [ "Sophia", "Olivia", "James" ],
323333
"city": "New York",
324334
"gene": "Y",
325335
"parent": "Jane Smith"
@@ -364,18 +374,18 @@ std::string GuideJtc::jtc_examples_{R"(
364374
]
365375
}
366376
]
367-
ors:
368-
jtc -w'<parent>l:' -j example.json
377+
or:
378+
jtc -w'<parent>l:' -jl example.json
369379
370380
371381
- an insert and update options could be subjected for a shell cli evaluation, e.g., say we want to
372382
capitalize all parent names in our JSON:
373-
jtc -tc -%w'<parent>l:' -%e%u echo {{}} \| tr "[:lower:]" "[:upper:]" \; example.json
383+
jtc -tc -w'<parent>l:' -eu echo {{}} \| tr "[:lower:]" "[:upper:]" \; example.json
374384
{
375385
"Relation": [
376386
{
377387
"age": 31,
378-
"children": [ "Sophia", "Olivia", "James", "James" ],
388+
"children": [ "Sophia", "Olivia", "James" ],
379389
"city": "New York",
380390
"gene": "Y",
381391
"parent": "JANE SMITH"
@@ -393,12 +403,12 @@ std::string GuideJtc::jtc_examples_{R"(
393403
394404
- to add a child "Victoria" into each record, but as the first child use update operation with
395405
templating:
396-
jtc -tc -%w'<children>l:' -%u'<children>l:' -%T'["Victoria", {}]' example.json
406+
jtc -tc -w'<children>l:' -u'<children>l:' -T'["Victoria", {}]' example.json
397407
{
398408
"Relation": [
399409
{
400410
"age": 31,
401-
"children": [ "Victoria", "Sophia", "Olivia", "James", "James" ],
411+
"children": [ "Victoria", "Sophia", "Olivia", "James" ],
402412
"city": "New York",
403413
"gene": "Y",
404414
"parent": "Jane Smith"
@@ -412,11 +422,14 @@ std::string GuideJtc::jtc_examples_{R"(
412422
}
413423
]
414424
}
425+
or:
426+
jtc -tc -w'<children>l:' -u'["Victoria", {}];' example.json
415427
416-
in that example, the destination point of an update (-%w), as well as the source point of the
428+
in the 1st example, the destination point of an update (-%w), as well as the source point of the
417429
update (-%u) are in the same input - `example.json`. In the template (-%T), the interpolation
418-
of `{}` token will result in the bare array of "children", making resulting array carrying
419-
"Victoria" as the first element
430+
of `{}` token will result in the naked array of "children", making resulting array carrying
431+
"Victoria" as the first element. -%T (and its interpolation token) here refers to the -%u walk
432+
in the 2nd example, -%u holds a template itself, which then refers to the -%w walk
420433
421434
422435
* for a complete user guide visit https://github.com/ldn-softdev/jtc/blob/master/User%20Guide.md

0 commit comments

Comments
 (0)