-
Notifications
You must be signed in to change notification settings - Fork 64
[main] Simplified jslinux command line options #1875
base: master
Are you sure you want to change the base?
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 <[email protected]>
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 <[email protected]>
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
braces for great justice
ZVAL global_obj = jerry_get_global_object(); | ||
ZVAL process = zjs_create_object(); | ||
|
||
while ((ptr = strchr(last, ' '))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Braces, or maybe change this to an assert?
@@ -299,6 +368,7 @@ int main(int argc, char *argv[]) | |||
|
|||
#ifdef ZJS_LINUX_BUILD | |||
zjs_free(script); | |||
init_process(js_args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 [email protected]