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

Add command-line option to sort object keys.

Closes #79.
This commit is contained in:
Stephen Dolan
2013-05-29 11:43:55 +01:00
parent 08cc591884
commit cc8761dbde
2 changed files with 10 additions and 2 deletions

View File

@ -113,7 +113,11 @@ sections:
"\u03bc"). Using this option, you can force jq to produce pure
ASCII output with every non-ASCII character replaced with the
equivalent escape sequence.
* `--sort-keys` / `-S`:
Output the fields of each object with the keys in sorted order.
* `--raw-output` / `-r`:
With this option, if the filter's result is a string then it

6
main.c
View File

@ -56,8 +56,9 @@ enum {
ASCII_OUTPUT = 32,
COLOUR_OUTPUT = 64,
NO_COLOUR_OUTPUT = 128,
SORTED_OUTPUT = 256,
FROM_FILE = 256,
FROM_FILE = 512,
/* debugging only */
DUMP_DISASM = 2048,
@ -82,6 +83,7 @@ static void process(jv value, int flags) {
#else
dumpopts = isatty(fileno(stdout)) ? JV_PRINT_COLOUR : 0;
#endif
if (options & SORTED_OUTPUT) dumpopts |= JV_PRINT_SORTED;
if (!(options & COMPACT_OUTPUT)) dumpopts |= JV_PRINT_PRETTY;
if (options & ASCII_OUTPUT) dumpopts |= JV_PRINT_ASCII;
if (options & COLOUR_OUTPUT) dumpopts |= JV_PRINT_COLOUR;
@ -197,6 +199,8 @@ int main(int argc, char* argv[]) {
options |= NO_COLOUR_OUTPUT;
} else if (isoption(argv[i], 'a', "ascii-output")) {
options |= ASCII_OUTPUT;
} else if (isoption(argv[i], 'S', "sort-keys")) {
options |= SORTED_OUTPUT;
} else if (isoption(argv[i], 'R', "raw-input")) {
options |= RAW_INPUT;
} else if (isoption(argv[i], 'n', "null-input")) {