[main] Simplified jslinux command line options#1875
[main] Simplified jslinux command line options#1875jprestwo wants to merge 2 commits intointel:masterfrom
Conversation
jslinux was manually parsing arguments which is ugly. The optarg functionality does argument parsing automatically. Also, a usage print was added in the case of invalid arguments or if --help was specified. Signed-off-by: James Prestwood <james.prestwood@intel.com>
The --jsargs, -j flag can now be used to pass command line arguments to the js script, via process.argv Signed-off-by: James Prestwood <james.prestwood@intel.com>
| printf("jslinux usage:\n"); | ||
| printf("\t--jsargs, -j \"<args>\" Pass args to js script via process\n"); | ||
| printf("\t--exit-time, -t <milli> Exit after a certain number of" | ||
| "milliseconds\n"); |
There was a problem hiding this comment.
need a space between 'of' and 'milliseconds'
| "milliseconds\n"); | ||
| printf("\t--noexit, -n Do not exit jslinux when no events" | ||
| " are present\n"); | ||
| printf("\t--unittest, -u Run jslinux unit tests\n"); |
There was a problem hiding this comment.
You can use a couple \t's here to line up the descriptions.
| static void usage(void) | ||
| { | ||
| printf("jslinux usage:\n"); | ||
| printf("\t--jsargs, -j \"<args>\" Pass args to js script via process\n"); |
There was a problem hiding this comment.
More normal usage style is shortcut first, and caps for arg names, e.g. something like:
\t-j, --jsargs="ARGS"\t\tPass args...
| { "noexit", no_argument, NULL, 'n' }, | ||
| { "unittest", no_argument, NULL, 'u' }, | ||
| { "debugger", no_argument, NULL, 'd' }, | ||
| { "help", no_argument, NULL, 'h' }, |
There was a problem hiding this comment.
Odd spacing here, maybe just don't try to line things up?
|
|
||
| opt = getopt_long(argc, argv, "j:t:nudh", main_options, NULL); | ||
| if (opt < 0) | ||
| break; |
| ZVAL global_obj = jerry_get_global_object(); | ||
| ZVAL process = zjs_create_object(); | ||
|
|
||
| while ((ptr = strchr(last, ' '))) { |
There was a problem hiding this comment.
I'd prefer you do the assignment outside of the condition. So probably make it a forever loop that you break out of.
| void init_process(char *args) | ||
| { | ||
| if (!args) | ||
| return; |
There was a problem hiding this comment.
Braces, or maybe change this to an assert?
|
|
||
| #ifdef ZJS_LINUX_BUILD | ||
| zjs_free(script); | ||
| init_process(js_args); |
There was a problem hiding this comment.
We should probably make this its own module, conditional based on usage w/ analyze, like other things. Otherwise it's just going to be overhead. Particularly when we don't really have a use case. :)
So perhaps split that out here for a separate PR?
jslinux was manually parsing arguments which is ugly.
The optarg functionality does argument parsing automatically.
Also, a usage print was added in the case of invalid arguments
or if --help was specified.
Signed-off-by: James Prestwood james.prestwood@intel.com