aboutsummaryrefslogtreecommitdiff
path: root/json-rpc-shell.c
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2020-09-05 06:00:52 +0200
committerPřemysl Eric Janouch <p@janouch.name>2020-09-05 06:07:45 +0200
commit984e5b4e7fc4e433008b32883ec6447e5c49bc29 (patch)
treeb4500ecfda2a63d13779c165878e6c3dae56dda8 /json-rpc-shell.c
parentd57a8bd3c7be5fdf3282d6d45c8dea1d50f3fac1 (diff)
downloadjson-rpc-shell-984e5b4e7fc4e433008b32883ec6447e5c49bc29.tar.gz
json-rpc-shell-984e5b4e7fc4e433008b32883ec6447e5c49bc29.tar.xz
json-rpc-shell-984e5b4e7fc4e433008b32883ec6447e5c49bc29.zip
Use saner defaults
So that most of the time users won't need to use any switches. --pretty-print has been inverted into jq's --compact-output, and --auto-id has been replaced with barely, if-at-all useful --null-as-id.
Diffstat (limited to 'json-rpc-shell.c')
-rw-r--r--json-rpc-shell.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/json-rpc-shell.c b/json-rpc-shell.c
index 10105cd..94baaf9 100644
--- a/json-rpc-shell.c
+++ b/json-rpc-shell.c
@@ -932,11 +932,11 @@ static struct app_context
struct config config; ///< Program configuration
enum color_mode color_mode; ///< Colour output mode
- bool pretty_print; ///< Whether to pretty print
+ bool compact; ///< Whether to not pretty print
bool verbose; ///< Print requests
bool trust_all; ///< Don't verify peer certificates
- bool auto_id; ///< Use automatically generated ID's
+ bool null_as_id; ///< JSON null is used as an ID
int64_t next_id; ///< Next autogenerated ID
iconv_t term_to_utf8; ///< Terminal encoding to UTF-8
@@ -2845,7 +2845,7 @@ process_response (struct app_context *ctx, const json_t *id, struct str *buf,
if (result)
{
int flags = JSON_ENCODE_ANY;
- if (ctx->pretty_print)
+ if (!ctx->compact)
flags |= JSON_INDENT (2);
char *utf8 = json_dumps (result, flags);
@@ -3041,9 +3041,16 @@ process_input (char *user_input, void *user_data)
*target = json_incref (args[i]);
}
- if (!id && ctx->auto_id)
+ if (!id)
id = json_integer (ctx->next_id++);
+ // Use nulls to send notifications, unless a special switch is used
+ if (!ctx->null_as_id && json_is_null (id))
+ {
+ json_decref (id);
+ id = NULL;
+ }
+
make_json_rpc_call (ctx, method, id, params, pipeline);
fail_parse:
@@ -3341,15 +3348,12 @@ parse_program_arguments (struct app_context *ctx, int argc, char **argv,
{ 'd', "debug", NULL, 0, "run in debug mode" },
{ 'h', "help", NULL, 0, "display this help message and exit" },
{ 'V', "version", NULL, 0, "output version information and exit" },
- // TODO: consider making this the default and instead adding
- // an option to accept JSON null as an id.
- { 'a', "auto-id", NULL, 0, "automatic `id' fields" },
+ { 'n', "null-as-id", NULL, 0, "JSON null is used as an `id'" },
{ 'o', "origin", "O", 0, "set the HTTP Origin header" },
- // TODO: consider inverting this to -c/--compact-output
- { 'p', "pretty", NULL, 0, "pretty-print the responses" },
+ { 'c', "compact-output", NULL, 0, "do not pretty-print responses" },
{ 't', "trust-all", NULL, 0, "don't care about SSL/TLS certificates" },
{ 'v', "verbose", NULL, 0, "print raw requests and responses" },
- { 'c', "color", "WHEN", OPT_LONG_ONLY,
+ { 'C', "color", "WHEN", OPT_LONG_ONLY,
"colorize output: never, always, or auto" },
{ 'w', "write-default-cfg", "FILENAME",
OPT_OPTIONAL_ARG | OPT_LONG_ONLY,
@@ -3375,12 +3379,12 @@ parse_program_arguments (struct app_context *ctx, int argc, char **argv,
exit (EXIT_SUCCESS);
case 'o': *origin = optarg; break;
- case 'a': ctx->auto_id = true; break;
- case 'p': ctx->pretty_print = true; break;
+ case 'n': ctx->null_as_id = true; break;
+ case 'c': ctx->compact = true; break;
case 't': ctx->trust_all = true; break;
case 'v': ctx->verbose = true; break;
- case 'c':
+ case 'C':
if (!strcasecmp (optarg, "never"))
ctx->color_mode = COLOR_NEVER;
else if (!strcasecmp (optarg, "always"))