From: Dmitry Volyntsev Date: Tue, 7 May 2019 16:50:38 +0000 (+0300) Subject: Shell: sorting arguments in alphabetic order. X-Git-Tag: 0.3.2~18 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=f3af89401294c69f68b4c568e5ee3ccd8e3aa32a;p=njs.git Shell: sorting arguments in alphabetic order. --- diff --git a/njs/njs_shell.c b/njs/njs_shell.c index d5560f0a..2e6d245b 100644 --- a/njs/njs_shell.c +++ b/njs/njs_shell.c @@ -30,15 +30,16 @@ typedef struct { + uint8_t disassemble; + uint8_t interactive; + uint8_t module; + uint8_t quiet; + uint8_t sandbox; + uint8_t version; + char *file; size_t n_paths; char **paths; - nxt_int_t version; - nxt_int_t disassemble; - nxt_int_t interactive; - nxt_int_t sandbox; - nxt_int_t quiet; - nxt_int_t module; } njs_opts_t; @@ -284,10 +285,10 @@ njs_get_options(njs_opts_t *opts, int argc, char** argv) "\n" "Options:\n" " -d print disassembled code.\n" + " -p set path prefix for modules.\n" " -q disable interactive introduction prompt.\n" " -s sandbox mode.\n" " -t script|module source code type (script is default).\n" - " -p set path prefix for modules.\n" " -v print njs version and exit.\n" " | - run code from a file or stdin.\n"; @@ -315,6 +316,23 @@ njs_get_options(njs_opts_t *opts, int argc, char** argv) opts->disassemble = 1; break; + case 'p': + if (++i < argc) { + opts->n_paths++; + paths = realloc(opts->paths, opts->n_paths * sizeof(char *)); + if (paths == NULL) { + nxt_error("failed to add path\n"); + return NXT_ERROR; + } + + opts->paths = paths; + opts->paths[opts->n_paths - 1] = argv[i]; + break; + } + + nxt_error("option \"-p\" requires directory name\n"); + return NXT_ERROR; + case 'q': opts->quiet = 1; break; @@ -339,24 +357,6 @@ njs_get_options(njs_opts_t *opts, int argc, char** argv) nxt_error("option \"-t\" requires source type\n"); return NXT_ERROR; - - case 'p': - if (++i < argc) { - opts->n_paths++; - paths = realloc(opts->paths, opts->n_paths * sizeof(char *)); - if (paths == NULL) { - nxt_error("failed to add path\n"); - return NXT_ERROR; - } - - opts->paths = paths; - opts->paths[opts->n_paths - 1] = argv[i]; - break; - } - - nxt_error("option \"-p\" requires directory name\n"); - return NXT_ERROR; - case 'v': case 'V': opts->version = 1; diff --git a/njs/test/njs_expect_test.exp b/njs/test/njs_expect_test.exp index 1b6861a8..592314ee 100644 --- a/njs/test/njs_expect_test.exp +++ b/njs/test/njs_expect_test.exp @@ -649,10 +649,6 @@ njs_run "-p njs/test/module ./njs/test/module/recursive.js" \ njs_run "-h" "Interactive njs shell.\r\n\r\nOptions:" -# version - -njs_run "-v" "\\d+\.\\d+\.\\d+" - # disassemble njs_test { @@ -664,32 +660,6 @@ njs_test { "00000 TRY START*\r\n*TRY RETURN*STOP*\r\n\r\nundefined"} } "-d" -# sandboxing - -njs_test { - {"var fs = require('fs')\r\n" - "Error: Cannot find module \"fs\"\r\n"} -} "-s" - -njs_test { - {"var crypto = require('crypto')\r\n" - "undefined\r\n"} -} "-s" - -# source type - -njs_test { - {"this\r\n" - "this\r\nundefined"} - {"(() => this)()\r\n" - "(() => this)()\r\nundefined"} -} "-t module" - -njs_test { - {"this.NaN\r\n" - "this.NaN\r\nNaN"} -} "-t script" - # modules njs_test { @@ -740,3 +710,36 @@ njs_run "-q ./njs/test/module/normal.js" \ njs_run "-p njs/test/module/libs/ -d ./njs/test/module/normal.js" \ "passed!" + +# sandboxing + +njs_test { + {"var fs = require('fs')\r\n" + "Error: Cannot find module \"fs\"\r\n"} +} "-s" + +njs_test { + {"var crypto = require('crypto')\r\n" + "undefined\r\n"} +} "-s" + + +# source type + +njs_test { + {"this\r\n" + "this\r\nundefined"} + {"(() => this)()\r\n" + "(() => this)()\r\nundefined"} +} "-t module" + +njs_test { + {"this.NaN\r\n" + "this.NaN\r\nNaN"} +} "-t script" + + +# version + +njs_run "-v" "\\d+\.\\d+\.\\d+" +