Skip to content

Commit b4742c1

Browse files
davidfetternicowilliams
authored andcommitted
Added rawfile
In passing, clean remnants of argfile from slurpfile docs.
1 parent 9a4576e commit b4742c1

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

docs/content/3.manual/manual.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,17 @@ sections:
236236
237237
This option reads all the JSON texts in the named file and binds
238238
an array of the parsed JSON values to the given global variable.
239-
If you run jq with `--argfile foo bar`, then `$foo` is available
239+
If you run jq with `--slurpfile foo bar`, then `$foo` is available
240240
in the program and has an array whose elements correspond to the
241241
texts in the file named `bar`.
242242
243+
* `--rawfile variable-name filename`:
244+
245+
This option reads in the named file and binds its contents to the given
246+
global variable. If you run jq with `--rawfile foo bar`, then `$foo` is
247+
available in the program and has a string whose contents are to the texs
248+
in the file named `bar`.
249+
243250
* `--argfile variable-name filename`:
244251
245252
Do not use. Use `--slurpfile` instead.

src/main.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ static void usage(int code, int keep_it_short) {
8383
" --arg a v set variable $a to value <v>;\n"
8484
" --argjson a v set variable $a to JSON value <v>;\n"
8585
" --slurpfile a f set variable $a to an array of JSON texts read from <f>;\n"
86+
" --rawfile a f set variable $a to a string consisting of the contents of <f>;\n"
8687
" --args remaining arguments are string arguments, not files;\n"
8788
" --jsonargs remaining arguments are JSON arguments, not files;\n"
8889
" -- terminates argument processing;\n\n"
@@ -443,18 +444,22 @@ int main(int argc, char* argv[]) {
443444
continue;
444445
}
445446
if (isoption(argv[i], 0, "argfile", &short_opts) ||
447+
isoption(argv[i], 0, "rawfile", &short_opts) ||
446448
isoption(argv[i], 0, "slurpfile", &short_opts)) {
449+
int raw = isoption(argv[i], 0, "rawfile", &short_opts);
447450
const char *which;
448451
if (isoption(argv[i], 0, "argfile", &short_opts))
449452
which = "argfile";
453+
else if (raw)
454+
which = "rawfile";
450455
else
451456
which = "slurpfile";
452457
if (i >= argc - 2) {
453458
fprintf(stderr, "%s: --%s takes two parameters (e.g. --%s varname filename)\n", progname, which, which);
454459
die();
455460
}
456461
if (!jv_object_has(jv_copy(program_arguments), jv_string(argv[i+1]))) {
457-
jv data = jv_load_file(argv[i+2], 0);
462+
jv data = jv_load_file(argv[i+2], raw);
458463
if (!jv_is_valid(data)) {
459464
data = jv_invalid_get_msg(data);
460465
fprintf(stderr, "%s: Bad JSON in --%s %s %s: %s\n", progname, which,

0 commit comments

Comments
 (0)