Added rawfile

In passing, clean remnants of argfile from slurpfile docs.
This commit is contained in:
David Fetter authored and Nicolas Williams committed 2017-12-11 12:17:17 -06:00
1 parent 9a4576e756
commit b4742c1257
2 files changed
+14 -2

No files matched your search

+8 -1
View File
@@ -236,10 +236,17 @@ sections:
This option reads all the JSON texts in the named file and binds This option reads all the JSON texts in the named file and binds
an array of the parsed JSON values to the given global variable. an array of the parsed JSON values to the given global variable.
If you run jq with `--argfile foo bar`, then `$foo` is available If you run jq with `--slurpfile foo bar`, then `$foo` is available
in the program and has an array whose elements correspond to the in the program and has an array whose elements correspond to the
texts in the file named `bar`. texts in the file named `bar`.
* `--rawfile variable-name filename`:
This option reads in the named file and binds its contents to the given
global variable. If you run jq with `--rawfile foo bar`, then `$foo` is
available in the program and has a string whose contents are to the texs
in the file named `bar`.
* `--argfile variable-name filename`: * `--argfile variable-name filename`:
Do not use. Use `--slurpfile` instead. Do not use. Use `--slurpfile` instead.
+6 -1
View File
@@ -83,6 +83,7 @@ static void usage(int code, int keep_it_short) {
" --arg a v set variable $a to value <v>;\n" " --arg a v set variable $a to value <v>;\n"
" --argjson a v set variable $a to JSON value <v>;\n" " --argjson a v set variable $a to JSON value <v>;\n"
" --slurpfile a f set variable $a to an array of JSON texts read from <f>;\n" " --slurpfile a f set variable $a to an array of JSON texts read from <f>;\n"
" --rawfile a f set variable $a to a string consisting of the contents of <f>;\n"
" --args remaining arguments are string arguments, not files;\n" " --args remaining arguments are string arguments, not files;\n"
" --jsonargs remaining arguments are JSON arguments, not files;\n" " --jsonargs remaining arguments are JSON arguments, not files;\n"
" -- terminates argument processing;\n\n" " -- terminates argument processing;\n\n"
@@ -443,10 +444,14 @@ int main(int argc, char* argv[]) {
continue; continue;
} }
if (isoption(argv[i], 0, "argfile", &short_opts) || if (isoption(argv[i], 0, "argfile", &short_opts) ||
isoption(argv[i], 0, "rawfile", &short_opts) ||
isoption(argv[i], 0, "slurpfile", &short_opts)) { isoption(argv[i], 0, "slurpfile", &short_opts)) {
int raw = isoption(argv[i], 0, "rawfile", &short_opts);
const char *which; const char *which;
if (isoption(argv[i], 0, "argfile", &short_opts)) if (isoption(argv[i], 0, "argfile", &short_opts))
which = "argfile"; which = "argfile";
else if (raw)
which = "rawfile";
else else
which = "slurpfile"; which = "slurpfile";
if (i >= argc - 2) { if (i >= argc - 2) {
@@ -454,7 +459,7 @@ int main(int argc, char* argv[]) {
die(); die();
} }
if (!jv_object_has(jv_copy(program_arguments), jv_string(argv[i+1]))) { if (!jv_object_has(jv_copy(program_arguments), jv_string(argv[i+1]))) {
jv data = jv_load_file(argv[i+2], 0); jv data = jv_load_file(argv[i+2], raw);
if (!jv_is_valid(data)) { if (!jv_is_valid(data)) {
data = jv_invalid_get_msg(data); data = jv_invalid_get_msg(data);
fprintf(stderr, "%s: Bad JSON in --%s %s %s: %s\n", progname, which, fprintf(stderr, "%s: Bad JSON in --%s %s %s: %s\n", progname, which,