summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Dolan <mu@netsoc.tcd.ie>2013-05-29 11:43:55 +0100
committerStephen Dolan <mu@netsoc.tcd.ie>2013-06-03 23:12:31 +0100
commitcc8761dbdeff9672e74e1be512c3ee0fb3ed6617 (patch)
treebc7b0ffb1e6d4831579c45e2cce11be1a997892b
parent08cc591884b034390ca9e9527792c7785475b09b (diff)
Add command-line option to sort object keys.
Closes #79.
-rw-r--r--docs/content/3.manual/manual.yml6
-rw-r--r--main.c6
2 files changed, 10 insertions, 2 deletions
diff --git a/docs/content/3.manual/manual.yml b/docs/content/3.manual/manual.yml
index df3c177e..7272c880 100644
--- a/docs/content/3.manual/manual.yml
+++ b/docs/content/3.manual/manual.yml
@@ -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
diff --git a/main.c b/main.c
index 822bc6ce..6d11f01d 100644
--- a/main.c
+++ b/main.c
@@ -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")) {