1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00

Improve usage message

This commit is contained in:
Nicolas Williams
2015-05-29 15:35:30 -05:00
parent 33874eb513
commit 74ecb88935

51
main.c
View File

@ -27,31 +27,32 @@ static void usage(int code) {
if (code == 0) if (code == 0)
f = stdout; f = stdout;
#ifdef BAIL int ret = fprintf(f,
#undef BAIL "jq - commandline JSON processor [version %s]\n"
#endif "Usage: %s [options] <jq filter> [file...]\n\n"
#define BAIL(expr) do { if ((expr) < 0 && code == 0) code = 2; } while (0) "\tjq is a tool for processing JSON inputs, applying the\n"
BAIL(fprintf(f, "\njq - commandline JSON processor [version %s]\n", JQ_VERSION)); "\tgiven filter to its JSON text inputs and producing the\n"
BAIL(fprintf(f, "Usage: %s [options] <jq filter> [file...]\n\n", progname)); "\tfilter's results as JSON on standard output.\n"
BAIL(fprintf(f, "\tjq is a tool for processing JSON inputs, applying the\n")); "\tThe simplest filter is ., which is the identity filter,\n"
BAIL(fprintf(f, "\tgiven filter to its JSON text inputs and producing the\n")); "\tcopying jq's input to its output unmodified (except for\n"
BAIL(fprintf(f, "\tfilter's results as JSON on standard output.\n")); "\tformatting).\n"
BAIL(fprintf(f, "\tThe simplest filter is ., which is the identity filter,\n")); "\tFor more advanced filters see the jq(1) manpage (\"man jq\")\n"
BAIL(fprintf(f, "\tcopying jq's input to its output.\n")); "\tand/or http://stedolan.github.com/jq\n\n"
BAIL(fprintf(f, "\tFor more advanced filters see the jq(1) manpage (\"man jq\")\n")); "\tSome of the options include:\n"
BAIL(fprintf(f, "\tand/or http://stedolan.github.com/jq\n\n")); "\t -c\t\tcompact instead of pretty-printed output;\n"
BAIL(fprintf(f, "\tSome of the options include:\n")); "\t -n\t\tuse `null` as the single input value;\n"
BAIL(fprintf(f, "\t -h\t\tthis message;\n")); "\t -e\t\tset the exit status code based on the output;\n"
BAIL(fprintf(f, "\t -c\t\tcompact instead of pretty-printed output;\n")); "\t -s\t\tread (slurp) all inputs into an array; apply filter to it;\n"
BAIL(fprintf(f, "\t -n\t\tuse `null` as the single input value;\n")); "\t -r\t\toutput raw strings, not JSON texts;\n"
BAIL(fprintf(f, "\t -s\t\tread (slurp) all inputs into an array; apply filter to it;\n")); "\t -R\t\tread raw strings, not JSON texts;\n"
BAIL(fprintf(f, "\t -r\t\toutput raw strings, not JSON texts;\n")); "\t -C\t\tcolorize JSON;\n"
BAIL(fprintf(f, "\t -R\t\tread raw strings, not JSON texts;\n")); "\t -M\t\tmonochrome (don't colorize JSON);\n"
BAIL(fprintf(f, "\t --arg a v\tset variable $a to value <v>;\n")); "\t -S\t\tsort keys of objects on output;\n"
BAIL(fprintf(f, "\t --argjson a v\tset variable $a to JSON value <v>;\n")); "\t --arg a v\tset variable $a to value <v>;\n"
BAIL(fprintf(f, "\t --slurpfile a f\tset variable $a to an array of JSON texts read from <f>;\n")); "\t --argjson a v\tset variable $a to JSON value <v>;\n"
BAIL(fprintf(f, "\tSee the manpage for more options.\n")); "\t --slurpfile a f\tset variable $a to an array of JSON texts read from <f>;\n"
exit(code); "\tSee the manpage for more options.\n", JQ_VERSION, progname);
exit((ret < 0 && code == 0) ? 2 : code);
} }
static void die() { static void die() {