Skip to content

Commit 54e7307

Browse files
committed
Add help flag and usage to UNIX Jerry standalone.
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
1 parent 920a9ee commit 54e7307

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

main-unix.c

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,27 @@ assert_handler (const jerry_api_object_t *function_obj_p __attr_unused___, /** <
188188
}
189189
} /* assert_handler */
190190

191+
static void
192+
print_usage ()
193+
{
194+
printf ("Usage: ./jerry [flags] [js-file ...]\n"
195+
"\n"
196+
"Flags:\n"
197+
" -h, --help\n"
198+
" -v, --version\n"
199+
" --mem-stats\n"
200+
" --mem-stats-separate\n"
201+
" --parse-only\n"
202+
" --show-opcodes\n"
203+
" --save-snapshot-for-global $output_file\n"
204+
" --save-snapshot-for-eval $output_file\n"
205+
" --exec-snapshot $input_file\n"
206+
" --log-level [0-3]\n"
207+
" --log-file $output_file\n"
208+
" --abort-on-fail\n"
209+
"\n");
210+
} /* print_usage */
211+
191212
int
192213
main (int argc,
193214
char **argv)
@@ -199,6 +220,11 @@ main (int argc,
199220

200221
return JERRY_STANDALONE_EXIT_CODE_FAIL;
201222
}
223+
else if (argc < 2)
224+
{
225+
print_usage ();
226+
return JERRY_STANDALONE_EXIT_CODE_FAIL;
227+
}
202228

203229
const char *file_names[JERRY_MAX_COMMAND_LINE_ARGS];
204230
int i;
@@ -226,12 +252,18 @@ main (int argc,
226252
#endif /* JERRY_ENABLE_LOG */
227253
for (i = 1; i < argc; i++)
228254
{
229-
if (!strcmp ("-v", argv[i]))
255+
if (!strcmp ("-h", argv[i]) || !strcmp ("--help", argv[i]))
256+
{
257+
print_usage ();
258+
return JERRY_STANDALONE_EXIT_CODE_OK;
259+
}
260+
if (!strcmp ("-v", argv[i]) || !strcmp ("--version", argv[i]))
230261
{
231262
printf ("Build date: \t%s\n", jerry_build_date);
232263
printf ("Commit hash:\t%s\n", jerry_commit_hash);
233264
printf ("Branch name:\t%s\n", jerry_branch_name);
234265
printf ("\n");
266+
return JERRY_STANDALONE_EXIT_CODE_OK;
235267
}
236268
else if (!strcmp ("--mem-stats", argv[i]))
237269
{
@@ -265,6 +297,7 @@ main (int argc,
265297
else
266298
{
267299
JERRY_ERROR_MSG ("Error: wrong format of the arguments\n");
300+
print_usage ();
268301
return JERRY_STANDALONE_EXIT_CODE_FAIL;
269302
}
270303
}
@@ -278,6 +311,7 @@ main (int argc,
278311
else
279312
{
280313
JERRY_ERROR_MSG ("Error: wrong format of the arguments\n");
314+
print_usage ();
281315
return JERRY_STANDALONE_EXIT_CODE_FAIL;
282316
}
283317
}
@@ -308,13 +342,19 @@ main (int argc,
308342
else
309343
{
310344
JERRY_ERROR_MSG ("Error: wrong format of the arguments\n");
345+
print_usage ();
311346
return JERRY_STANDALONE_EXIT_CODE_FAIL;
312347
}
313348
}
314349
else if (!strcmp ("--abort-on-fail", argv[i]))
315350
{
316351
flags |= JERRY_FLAG_ABORT_ON_FAIL;
317352
}
353+
else if (!strncmp ("-", argv[i], 1))
354+
{
355+
print_usage ();
356+
return JERRY_STANDALONE_EXIT_CODE_FAIL;
357+
}
318358
else
319359
{
320360
file_names[files_counter++] = argv[i];

0 commit comments

Comments
 (0)