summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Dolan <mu@netsoc.tcd.ie>2012-09-18 23:37:46 +0100
committerStephen Dolan <mu@netsoc.tcd.ie>2012-09-18 23:37:46 +0100
commit305059ff9f630b7fb140ef61fab5613483a75ff0 (patch)
tree84dd275e56ec0fa28e3cf8fd4aed0ae509bd594d
parent5863160112ac8b50f8b7b7da60044a78f8f261de (diff)
Usage messages if jq is run with no arguments.
Beats segfaulting.
-rw-r--r--main.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/main.c b/main.c
index 776c9575..92a7c652 100644
--- a/main.c
+++ b/main.c
@@ -8,7 +8,20 @@
#include "parser.h"
#include "execute.h"
+static const char* progname;
+
+static void usage() {
+ fprintf(stderr, "\njq - commandline JSON processor\n");
+ fprintf(stderr, "Usage: %s <jq filter>\n\n", progname);
+ fprintf(stderr, "For a description of how to write jq filters and\n");
+ fprintf(stderr, "why you might want to, see the jq documentation at\n");
+ fprintf(stderr, "http://stedolan.github.com/jq\n\n");
+ exit(1);
+}
+
int main(int argc, char* argv[]) {
+ if (argc) progname = argv[0];
+ if (argc != 2 || !strcmp(argv[1], "--help") || !strcmp(argv[1], "--version")) usage();
struct bytecode* bc = jq_compile(argv[1]);
if (!bc) return 1;