]> git.kaiwu.me - njs.git/commitdiff
Reporting njs version by CLI.
authorDmitry Volyntsev <xeioex@nginx.com>
Fri, 9 Feb 2018 16:16:18 +0000 (19:16 +0300)
committerDmitry Volyntsev <xeioex@nginx.com>
Fri, 9 Feb 2018 16:16:18 +0000 (19:16 +0300)
njs/njs.c
njs/test/njs_expect_test.exp

index 80c7ed8d1a5b21f1c944c6ae644d386a4abecaad..5c97b5240390b0a53c46b0c943bae6b1af87a4a9 100644 (file)
--- a/njs/njs.c
+++ b/njs/njs.c
@@ -41,6 +41,7 @@ typedef enum {
 
 typedef struct {
     char                    *file;
+    nxt_int_t               version;
     nxt_int_t               disassemble;
     nxt_int_t               interactive;
 } njs_opts_t;
@@ -137,6 +138,11 @@ main(int argc, char **argv)
         return (ret == NXT_DONE) ? EXIT_SUCCESS : EXIT_FAILURE;
     }
 
+    if (opts.version != 0) {
+        printf("%s\n", NJS_VERSION);
+        return EXIT_SUCCESS;
+    }
+
     mcp = nxt_mem_cache_pool_create(&njs_vm_mem_cache_pool_proto, NULL,
                                     NULL, 2 * nxt_pagesize(), 128, 512, 16);
     if (nxt_slow_path(mcp == NULL)) {
@@ -189,6 +195,10 @@ njs_get_options(njs_opts_t *opts, int argc, char** argv)
             opts->disassemble = 1;
             break;
 
+        case 'V':
+            opts->version = 1;
+            break;
+
         default:
             fprintf(stderr, "Unknown argument: \"%s\"\n", argv[i]);
             ret = NXT_ERROR;
@@ -197,7 +207,7 @@ njs_get_options(njs_opts_t *opts, int argc, char** argv)
 
         case 'h':
         case '?':
-            printf("Usage: %s [<file>|-] [-d]\n", argv[0]);
+            printf("Usage: %s [<file>|-] [-dV]\n", argv[0]);
             return ret;
         }
     }
@@ -254,7 +264,7 @@ njs_interactive_shell(njs_opts_t *opts, njs_vm_opt_t *vm_options)
         return NXT_ERROR;
     }
 
-    printf("interactive njscript\n\n");
+    printf("interactive njscript %s\n\n", NJS_VERSION);
 
     printf("v.<Tab> -> the properties and prototype methods of v.\n");
     printf("type console.help() for more information\n\n");
index 20d9feb9cc610dcdba235439e02c1e73ae729e09..ea04155f2fec69d4f9659eb3e3ae0383ae7cc3b0 100644 (file)
@@ -5,9 +5,8 @@
 
 proc njs_test {body} {
     spawn  -nottycopy njs
-    expect "interactive njscript\r
-\r
-v.<Tab> -> the properties and prototype methods of v.\r
+    expect -re "interactive njscript \\d+\.\\d+\.\\d+\r\n\r"
+    expect "v.<Tab> -> the properties and prototype methods of v.\r
 type console.help() for more information\r
 \r
 >> "