fix usage in help to use `jq` not the invoked command path (#3299)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by itchyny · committed by GitHub · parent 8819eb8 · Browse files · 1 file·+17 added−26 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+17 added−26 removed
- other:+17 added−26 removed
Provenance
- Commit
5f7b1ae- Tree
e86971c- Author
itchyny <itchyny@cybozu.co.jp>- Committer
GitHub <noreply@github.com>- Parent
8819eb8
1 file changed+17 added−26 removed
modified:src/main.c+17 added-26 removed
28 unmodified lines29 #if defined(HAVE_ISATTY) || defined(HAVE__ISATTY)30 #define USE_ISATTY31 #endif32 33-#include "compile.h"33 #include "jv.h"34 #include "jq.h"36-#include "jv_alloc.h"35 #include "util.h"36 37 int jq_testsuite(jv lib_dirs, int verbose, int argc, char* argv[]);38 41-static const char* progname;42-39 /*40 * For a longer help message we could use a better option parsing41 * strategy, one that lets stack options.42 */4 unmodified lines47 f = stdout;48 49 int ret = fprintf(f,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"54 "jq is a tool for processing JSON inputs, applying the given filter to\n"55 "its JSON text inputs and producing the filter's results as JSON on\n"56 "standard output.\n\n"57 "The simplest filter is ., which copies jq's input to its output\n"58 "unmodified except for formatting. For more advanced filters see\n"59 "the jq(1) manpage (\"man jq\") and/or https://jqlang.org/.\n\n"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);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");64 } else {65 (void) fprintf(f,66 "Command options:\n"67 " -n, --null-input use `null` as the single input value;\n"42 unmodified lines110 exit((ret < 0 && code == 0) ? 2 : code);111 }112 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");115 fprintf(stderr, "or see the jq manpage, or online docs at https://jqlang.org\n");116 exit(2);117 }118 194 unmodified lines313 314 jv ARGS = jv_array(); /* positional arguments */315 jv program_arguments = jv_object(); /* named arguments */316 324- if (argc) progname = argv[0];325-317 jq = jq_init();318 if (jq == NULL) {319 perror("jq_init");320 ret = JQ_ERROR_SYSTEM;18 unmodified lines339 ARGS = jv_array_append(ARGS, jv_string(argv[i]));340 } else if (further_args_are_json) {341 jv v = jv_parse(argv[i]);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");344 die();345 }346 ARGS = jv_array_append(ARGS, v);347 } else {68 unmodified lines416 dumpopts &= ~JV_PRINT_INDENT_FLAGS(7);417 dumpopts |= JV_PRINT_TAB | JV_PRINT_PRETTY;418 } else if (isoption(&text, 0, "indent", is_short)) {419 if (i >= argc - 1) {429- fprintf(stderr, "%s: --indent takes one parameter\n", progname);420+ fprintf(stderr, "jq: --indent takes one parameter\n");421 die();422 }423 dumpopts &= ~(JV_PRINT_TAB | JV_PRINT_INDENT_FLAGS(7));424 int indent = atoi(argv[i+1]);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");427 die();428 }429 dumpopts |= JV_PRINT_INDENT_FLAGS(indent);430 i++;12 unmodified lines443 further_args_are_strings = 0;444 further_args_are_json = 1;445 } else if (isoption(&text, 0, "arg", is_short)) {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");448 die();449 }450 if (!jv_object_has(jv_copy(program_arguments), jv_string(argv[i+1])))451 program_arguments = jv_object_set(program_arguments, jv_string(argv[i+1]), jv_string(argv[i+2]));452 i += 2; // skip the next two arguments453 } else if (isoption(&text, 0, "argjson", is_short)) {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");456 die();457 }458 if (!jv_object_has(jv_copy(program_arguments), jv_string(argv[i+1]))) {459 jv v = jv_parse(argv[i+2]);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");462 die();463 }464 program_arguments = jv_object_set(program_arguments, jv_string(argv[i+1]), v);465 }1 unmodified line467 } else if ((raw = isoption(&text, 0, "rawfile", is_short)) ||468 isoption(&text, 0, "slurpfile", is_short)) {469 const char *which = raw ? "rawfile" : "slurpfile";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);472 die();473 }474 if (!jv_object_has(jv_copy(program_arguments), jv_string(argv[i+1]))) {475 jv data = jv_load_file(argv[i+2], raw);476 if (!jv_is_valid(data)) {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,479 argv[i+1], argv[i+2], jv_string_value(data));480 jv_free(data);481 ret = JQ_ERROR_SYSTEM;482 goto out;26 unmodified lines509 argc - i, argv + i);510 goto out;511 } else {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]);514 } else {524- fprintf(stderr, "%s: Unknown option --%s\n", progname, text);515+ fprintf(stderr, "jq: Unknown option --%s\n", text);516 }517 die();518 }519 }69 unmodified lines589 590 jv data = jv_load_file(program, 1);591 if (!jv_is_valid(data)) {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));594 jv_free(data);595 ret = JQ_ERROR_SYSTEM;596 goto out;597 }108 unmodified lines