Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

[main] Simplified jslinux command line options #1875

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jprestwo
Copy link
Contributor

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]

James Prestwood added 2 commits April 19, 2018 10:01
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");
Copy link
Contributor

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");
Copy link
Contributor

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");
Copy link
Contributor

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' },
Copy link
Contributor

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;
Copy link
Contributor

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, ' '))) {
Copy link
Contributor

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;
Copy link
Contributor

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);
Copy link
Contributor

@grgustaf grgustaf Apr 23, 2018

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants