uint8_t version;
char *file;
+ char *command;
size_t n_paths;
char **paths;
} njs_opts_t;
main(int argc, char **argv)
{
char path[MAXPATHLEN], *p;
+ njs_vm_t *vm;
nxt_int_t ret;
njs_opts_t opts;
+ nxt_str_t command;
njs_vm_opt_t vm_options;
nxt_memzero(&opts, sizeof(njs_opts_t));
goto done;
}
- memcpy(path + nxt_strlen(path), "/shell", sizeof("/shell"));
+ if (opts.command == NULL) {
+ memcpy(path + nxt_strlen(path), "/shell", sizeof("/shell"));
+
+ } else {
+ memcpy(path + nxt_strlen(path), "/string", sizeof("/string"));
+ }
+
opts.file = path;
}
if (opts.interactive) {
ret = njs_interactive_shell(&opts, &vm_options);
+ } else if (opts.command) {
+ vm = njs_create_vm(&opts, &vm_options);
+ if (vm != NULL) {
+ command.start = (u_char *) opts.command;
+ command.length = nxt_strlen(opts.command);
+ ret = njs_process_script(vm_options.external, &opts, &command);
+ }
+
} else {
ret = njs_process_file(&opts, &vm_options);
}
"Interactive njs shell.\n"
"\n"
"Options:\n"
+ " -c specify the command to execute.\n"
" -d print disassembled code.\n"
" -p set path prefix for modules.\n"
" -q disable interactive introduction prompt.\n"
(void) write(STDIN_FILENO, help, nxt_length(help));
return ret;
+ case 'c':
+ opts->interactive = 0;
+
+ if (++i < argc) {
+ opts->command = argv[i];
+ break;
+ }
+
+ nxt_error("option \"-c\" requires argument\n");
+ return NXT_ERROR;
+
case 'd':
opts->disassemble = 1;
break;