Improve a few minor JSON glitches
Phil Sutter
reviewercover Improve a few minor JSON glitches
As suggested offline, print newline at end of JSON output (patch 1) and don't ignore -j flag if JSON support is not compiled-in - bail instead (patch 2).
Phil Sutter (2):
json: Print newline at end of list output
main: Bail if non-available JSON was requested
src/json.c | 2 ++ src/main.c | 3 +++ 2 files changed, 5 insertions(+)
Signature · 1 line
2.21.0
Phil Sutter
reviewerPATCH 1/2 json: Print newline at end of list output
If listing ruleset elements with '-j' flag, print a final newline to not upset shell prompts.
--- src/json.c | 2 ++ 1 file changed, 2 insertions(+)
src/json.c +2 -0
@@ -1752,6 +1752,8 @@ int do_command_list_json(struct netlink_ctx *ctx, struct cmd *cmd) root =json_pack ("{s:o}" ,"nftables" , root);json_dumpf (root, ctx->nft->output.output_fp,0 );json_decref (root); +fprintf (ctx->nft->output.output_fp,"\n" ); +fflush (ctx->nft->output.output_fp);return 0 ; }
Signature · 1 line
2.21.0
Phil Sutter
reviewerPATCH 2/2 main: Bail if non-available JSON was requested
In reply to Phil SutterIf user passes '-j' flag, falling back to standard syntax output probably causes more harm than good so instead print an error message and exit(1).
--- src/main.c | 3 +++ 1 file changed, 3 insertions(+)
src/main.c +3 -0
@@ -277,6 +277,9 @@ int main(int argc, char * const *argv)case OPT_JSON :#ifdef HAVE_LIBJANSSON output_flags |=NFT_CTX_OUTPUT_JSON ; +#else +fprintf (stderr,"JSON support not compiled-in\n" ); +exit (EXIT_FAILURE );#endif break ;case OPT_GUID :
Signature · 1 line
2.21.0
Quoted 3 lines · Phil Sutter
As suggested offline, print newline at end of JSON output (patch 1) and don't ignore -j flag if JSON support is not compiled-in - bail instead (patch 2).
Applied.