@@ -30,16 +30,12 @@ extern void jv_tsd_dtoa_ctx_init();
30
30
#define USE_ISATTY
31
31
#endif
32
32
33
- #include "compile.h"
34
33
#include "jv.h"
35
34
#include "jq.h"
36
- #include "jv_alloc.h"
37
35
#include "util.h"
38
36
39
37
int jq_testsuite (jv lib_dirs , int verbose , int argc , char * argv []);
40
38
41
- static const char * progname ;
42
-
43
39
/*
44
40
* For a longer help message we could use a better option parsing
45
41
* strategy, one that lets stack options.
@@ -52,22 +48,19 @@ static void usage(int code, int keep_it_short) {
52
48
53
49
int ret = fprintf (f ,
54
50
"jq - commandline JSON processor [version %s]\n"
55
- "\nUsage:\t%s [options] <jq filter> [file...]\n"
56
- "\t%s [options] --args <jq filter> [strings...]\n"
57
- "\t%s [options] --jsonargs <jq filter> [JSON_TEXTS...]\n\n"
51
+ "\nUsage:\tjq [options] <jq filter> [file...]\n"
52
+ "\tjq [options] --args <jq filter> [strings...]\n"
53
+ "\tjq [options] --jsonargs <jq filter> [JSON_TEXTS...]\n\n"
58
54
"jq is a tool for processing JSON inputs, applying the given filter to\n"
59
55
"its JSON text inputs and producing the filter's results as JSON on\n"
60
56
"standard output.\n\n"
61
57
"The simplest filter is ., which copies jq's input to its output\n"
62
58
"unmodified except for formatting. For more advanced filters see\n"
63
59
"the jq(1) manpage (\"man jq\") and/or https://jqlang.org/.\n\n"
64
60
"Example:\n\n\t$ echo '{\"foo\": 0}' | jq .\n"
65
- "\t{\n\t \"foo\": 0\n\t}\n\n" ,
66
- JQ_VERSION , progname , progname , progname );
61
+ "\t{\n\t \"foo\": 0\n\t}\n\n" , JQ_VERSION );
67
62
if (keep_it_short ) {
68
- fprintf (f ,
69
- "For listing the command options, use %s --help.\n" ,
70
- progname );
63
+ fprintf (f , "For listing the command options, use jq --help.\n" );
71
64
} else {
72
65
(void ) fprintf (f ,
73
66
"Command options:\n"
@@ -118,7 +111,7 @@ static void usage(int code, int keep_it_short) {
118
111
}
119
112
120
113
static void die () {
121
- fprintf (stderr , "Use %s --help for help with command-line options,\n" , progname );
114
+ fprintf (stderr , "Use jq --help for help with command-line options,\n" );
122
115
fprintf (stderr , "or see the jq manpage, or online docs at https://jqlang.org\n" );
123
116
exit (2 );
124
117
}
@@ -321,8 +314,6 @@ int main(int argc, char* argv[]) {
321
314
jv ARGS = jv_array (); /* positional arguments */
322
315
jv program_arguments = jv_object (); /* named arguments */
323
316
324
- if (argc ) progname = argv [0 ];
325
-
326
317
jq = jq_init ();
327
318
if (jq == NULL ) {
328
319
perror ("jq_init" );
@@ -349,7 +340,7 @@ int main(int argc, char* argv[]) {
349
340
} else if (further_args_are_json ) {
350
341
jv v = jv_parse (argv [i ]);
351
342
if (!jv_is_valid (v )) {
352
- fprintf (stderr , "%s : invalid JSON text passed to --jsonargs\n" , progname );
343
+ fprintf (stderr , "jq : invalid JSON text passed to --jsonargs\n" );
353
344
die ();
354
345
}
355
346
ARGS = jv_array_append (ARGS , v );
@@ -426,13 +417,13 @@ int main(int argc, char* argv[]) {
426
417
dumpopts |= JV_PRINT_TAB | JV_PRINT_PRETTY ;
427
418
} else if (isoption (& text , 0 , "indent" , is_short )) {
428
419
if (i >= argc - 1 ) {
429
- fprintf (stderr , "%s : --indent takes one parameter\n" , progname );
420
+ fprintf (stderr , "jq : --indent takes one parameter\n" );
430
421
die ();
431
422
}
432
423
dumpopts &= ~(JV_PRINT_TAB | JV_PRINT_INDENT_FLAGS (7 ));
433
424
int indent = atoi (argv [i + 1 ]);
434
425
if (indent < -1 || indent > 7 ) {
435
- fprintf (stderr , "%s : --indent takes a number between -1 and 7\n" , progname );
426
+ fprintf (stderr , "jq : --indent takes a number between -1 and 7\n" );
436
427
die ();
437
428
}
438
429
dumpopts |= JV_PRINT_INDENT_FLAGS (indent );
@@ -453,21 +444,21 @@ int main(int argc, char* argv[]) {
453
444
further_args_are_json = 1 ;
454
445
} else if (isoption (& text , 0 , "arg" , is_short )) {
455
446
if (i >= argc - 2 ) {
456
- fprintf (stderr , "%s : --arg takes two parameters (e.g. --arg varname value)\n" , progname );
447
+ fprintf (stderr , "jq : --arg takes two parameters (e.g. --arg varname value)\n" );
457
448
die ();
458
449
}
459
450
if (!jv_object_has (jv_copy (program_arguments ), jv_string (argv [i + 1 ])))
460
451
program_arguments = jv_object_set (program_arguments , jv_string (argv [i + 1 ]), jv_string (argv [i + 2 ]));
461
452
i += 2 ; // skip the next two arguments
462
453
} else if (isoption (& text , 0 , "argjson" , is_short )) {
463
454
if (i >= argc - 2 ) {
464
- fprintf (stderr , "%s : --argjson takes two parameters (e.g. --argjson varname text)\n" , progname );
455
+ fprintf (stderr , "jq : --argjson takes two parameters (e.g. --argjson varname text)\n" );
465
456
die ();
466
457
}
467
458
if (!jv_object_has (jv_copy (program_arguments ), jv_string (argv [i + 1 ]))) {
468
459
jv v = jv_parse (argv [i + 2 ]);
469
460
if (!jv_is_valid (v )) {
470
- fprintf (stderr , "%s : invalid JSON text passed to --argjson\n" , progname );
461
+ fprintf (stderr , "jq : invalid JSON text passed to --argjson\n" );
471
462
die ();
472
463
}
473
464
program_arguments = jv_object_set (program_arguments , jv_string (argv [i + 1 ]), v );
@@ -477,14 +468,14 @@ int main(int argc, char* argv[]) {
477
468
isoption (& text , 0 , "slurpfile" , is_short )) {
478
469
const char * which = raw ? "rawfile" : "slurpfile" ;
479
470
if (i >= argc - 2 ) {
480
- fprintf (stderr , "%s : --%s takes two parameters (e.g. --%s varname filename)\n" , progname , which , which );
471
+ fprintf (stderr , "jq : --%s takes two parameters (e.g. --%s varname filename)\n" , which , which );
481
472
die ();
482
473
}
483
474
if (!jv_object_has (jv_copy (program_arguments ), jv_string (argv [i + 1 ]))) {
484
475
jv data = jv_load_file (argv [i + 2 ], raw );
485
476
if (!jv_is_valid (data )) {
486
477
data = jv_invalid_get_msg (data );
487
- fprintf (stderr , "%s : Bad JSON in --%s %s %s: %s\n" , progname , which ,
478
+ fprintf (stderr , "jq : Bad JSON in --%s %s %s: %s\n" , which ,
488
479
argv [i + 1 ], argv [i + 2 ], jv_string_value (data ));
489
480
jv_free (data );
490
481
ret = JQ_ERROR_SYSTEM ;
@@ -519,9 +510,9 @@ int main(int argc, char* argv[]) {
519
510
goto out ;
520
511
} else {
521
512
if (is_short ) {
522
- fprintf (stderr , "%s : Unknown option -%c\n" , progname , text [0 ]);
513
+ fprintf (stderr , "jq : Unknown option -%c\n" , text [0 ]);
523
514
} else {
524
- fprintf (stderr , "%s : Unknown option --%s\n" , progname , text );
515
+ fprintf (stderr , "jq : Unknown option --%s\n" , text );
525
516
}
526
517
die ();
527
518
}
@@ -599,7 +590,7 @@ int main(int argc, char* argv[]) {
599
590
jv data = jv_load_file (program , 1 );
600
591
if (!jv_is_valid (data )) {
601
592
data = jv_invalid_get_msg (data );
602
- fprintf (stderr , "%s : %s\n" , progname , jv_string_value (data ));
593
+ fprintf (stderr , "jq : %s\n" , jv_string_value (data ));
603
594
jv_free (data );
604
595
ret = JQ_ERROR_SYSTEM ;
605
596
goto out ;
0 commit comments