]> git.kaiwu.me - njs.git/commitdiff
Shell: sorting arguments in alphabetic order.
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 7 May 2019 16:50:38 +0000 (19:50 +0300)
committerDmitry Volyntsev <xeioex@nginx.com>
Tue, 7 May 2019 16:50:38 +0000 (19:50 +0300)
njs/njs_shell.c
njs/test/njs_expect_test.exp

index d5560f0ace29601558a1c7f6e9f547d667a65959..2e6d245bb0a4fe0faabba5dc0bb91ec4c8e368c2 100644 (file)
 
 
 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"
         "  <filename> | -    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;
index 1b6861a83df81ae9c9aa45c4157117df24c35286..592314ee7445a2a3ee07d7a7521e4b8071b91598 100644 (file)
@@ -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+"
+