I just committed a new version of srfsh.c in trunk. I'm giving everybody a
heads-up because it may not be compatible with existing srfsh scripts.
The reason for the new version is to use a newer JSON parser. The upside is
that the new parser is at least twice as fast as the old one, and does a much
better job of detecting syntax errors.
The downside is that, since it's more strict about JSON syntax, it may reject
some existing srfsh scripts that the old parser would have accepted. (Note
however that the error messages explaining syntax errors now go to standard
error, so you don't have to dig through the log to figure out what you did
wrong).
As a side effect of these changes, there is a subtle difference in the way
srfsh handles commas on the srfsh command line.
Consider the classic srfsh example, where the last two arguments are treated as
JSON strings:
request opensrf.math add 2 2
Both the old srfsh and the new srfsh will let you separate the JSON string
arguments with an optional comma:
request opensrf.math add 2, 2
Unlike the old srfsh, the new srfsh extends this option to the non-JSON
arguments:
request opensrf.math, add 2 2
Both versions also accept multiple commas between JSON arguments. However the
old srfsh will accept any combination of commas and white space. The new srfsh
accepts multiple commas only if no two of them are adjacent, and only if none
of them immediately precedes the argument on the right. For example, the
following two commands are accepted by the old srfsh but not by the new one:
request opensrf.math add 2,,, 2
request opensrf.math add 2 ,2
Both versions accept the following:
request opensrf.math add 2, , , 2
The treatment of multiple commas is more detail than you're likely to care
about, but if you have trouble running an existing script through the new
srfsh, it's something to keep in mind.
----------
Another minor change is the treatment of white space within a quoted
string literal.
The old srfsh would break up the command line mostly on the basis of
white space. If a quoted string literal contained multiple consecutive white
space characters, they would be collapsed into a single blank space. For
example, "abc xyz" would become "abc xyz". The new srfsh preserves all
white space within a quoted string literal.
I doubt that you will ever notice that little change, but it's there.
----------
As long as I'm on the subject of srfsh, I'd like to mention a change that
happened some time ago in trunk but was not publicly announced, so far as I
know.
You can now break up a srfsh command line into multiple physical lines, as long
as all but the last physical line is terminated by a backslash immediately
before the newline. For example:
request open-ils.cstore open-ils.cstore.direct.actor.org_unit.search \
{ "ou_type": { \
"in": { \
"from":"aout", \
"select":{ "aout":[ "id" ] }, \
"where":{ "depth": {"<":2} } \
} } }, {"order_by": { "aou" : "name" } }
This convention resembles that use by, for example, C and shell.
As a result, you can format your scripts to be more readable instead of
creating big long messy single lines.
Scott McKellar