diff --git a/main.c b/main.c index 36ee20f7..7a91f038 100644 --- a/main.c +++ b/main.c @@ -22,27 +22,30 @@ static const char* progname; * strategy, one that lets stack options. */ static void usage(int code) { - fprintf(stderr, "\njq - commandline JSON processor [version %s]\n", JQ_VERSION); - fprintf(stderr, "Usage: %s [options] [file...]\n\n", progname); - fprintf(stderr, "\tjq is a tool for processing JSON inputs, applying the\n"); - fprintf(stderr, "\tgiven filter to its JSON text inputs and producing the\n"); - fprintf(stderr, "\tfilter's results as JSON on standard output.\n"); - fprintf(stderr, "\tThe simplest filter is ., which is the identity filter,\n"); - fprintf(stderr, "\tcopying jq's input to its output.\n"); - fprintf(stderr, "\tFor more advanced filters see the jq(1) manpage (\"man jq\")\n"); - fprintf(stderr, "\tand/or http://stedolan.github.com/jq\n\n"); - fprintf(stderr, "\tSome of the options include:\n"); - fprintf(stderr, "\t -h\t\tthis message;\n"); - fprintf(stderr, "\t -c\t\tcompact instead of pretty-printed output;\n"); - fprintf(stderr, "\t -n\t\tuse `null` as the single input value;\n"); - fprintf(stderr, "\t -i\t\tedit the [first] file in-place;\n"); - fprintf(stderr, "\t -s\t\tread (slurp) all inputs into an array; apply filter to it;\n"); - fprintf(stderr, "\t -r\t\toutput raw strings, not JSON texts;\n"); - fprintf(stderr, "\t -R\t\tread raw strings, not JSON texts;\n"); - fprintf(stderr, "\t --arg a v\tset variable $a to value ;\n"); - fprintf(stderr, "\t --argjson a v\tset variable $a to JSON value ;\n"); - fprintf(stderr, "\t --argfile a f\tset variable $a to JSON texts read from ;\n"); - fprintf(stderr, "\tSee the manpage for more options.\n"); + FILE *f = stderr; + if (code == 0) + f = stdout; + fprintf(f, "\njq - commandline JSON processor [version %s]\n", JQ_VERSION); + fprintf(f, "Usage: %s [options] [file...]\n\n", progname); + fprintf(f, "\tjq is a tool for processing JSON inputs, applying the\n"); + fprintf(f, "\tgiven filter to its JSON text inputs and producing the\n"); + fprintf(f, "\tfilter's results as JSON on standard output.\n"); + fprintf(f, "\tThe simplest filter is ., which is the identity filter,\n"); + fprintf(f, "\tcopying jq's input to its output.\n"); + fprintf(f, "\tFor more advanced filters see the jq(1) manpage (\"man jq\")\n"); + fprintf(f, "\tand/or http://stedolan.github.com/jq\n\n"); + fprintf(f, "\tSome of the options include:\n"); + fprintf(f, "\t -h\t\tthis message;\n"); + fprintf(f, "\t -c\t\tcompact instead of pretty-printed output;\n"); + fprintf(f, "\t -n\t\tuse `null` as the single input value;\n"); + fprintf(f, "\t -i\t\tedit the [first] file in-place;\n"); + fprintf(f, "\t -s\t\tread (slurp) all inputs into an array; apply filter to it;\n"); + fprintf(f, "\t -r\t\toutput raw strings, not JSON texts;\n"); + fprintf(f, "\t -R\t\tread raw strings, not JSON texts;\n"); + fprintf(f, "\t --arg a v\tset variable $a to value ;\n"); + fprintf(f, "\t --argjson a v\tset variable $a to JSON value ;\n"); + fprintf(f, "\t --argfile a f\tset variable $a to JSON texts read from ;\n"); + fprintf(f, "\tSee the manpage for more options.\n"); exit(code); }