From b330fa5e79d87686fa718b8e627b98ceeb546256 Mon Sep 17 00:00:00 2001 From: mhogomchungu Date: Thu, 21 May 2026 18:58:57 +0300 Subject: [PATCH 1/4] Add an option to print only version info --- qjs.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/qjs.c b/qjs.c index 939e151d4..2879f8114 100644 --- a/qjs.c +++ b/qjs.c @@ -468,6 +468,10 @@ int main(int argc, char **argv) help(); continue; } + if (opt == 'v' || !strcmp(longopt, "version")) { + printf("QuickJS-ng version %s\n",JS_GetVersion()); + return 0; + } if (opt == 'e' || !strcmp(longopt, "eval")) { if (!optarg) { if (optind >= argc) { From 246242772e281e54f99e869c3d6bf62fdcea8621 Mon Sep 17 00:00:00 2001 From: mhogomchungu Date: Thu, 21 May 2026 19:49:13 +0300 Subject: [PATCH 2/4] Return correct exit status when a user asks for a list of options --- qjs.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/qjs.c b/qjs.c index 2879f8114..66561e5f3 100644 --- a/qjs.c +++ b/qjs.c @@ -372,7 +372,7 @@ static const JSMallocFunctions mi_mf = { #define PROG_NAME "qjs" -void help(void) +void help(int exit_status) { printf("QuickJS-ng version %s\n" "usage: " PROG_NAME " [options] [file [args]]\n" @@ -392,7 +392,7 @@ void help(void) " --memory-limit n limit the memory usage to 'n' Kbytes\n" " --stack-size n limit the stack size to 'n' Kbytes\n" "-q --quit just instantiate the interpreter and quit\n", JS_GetVersion()); - exit(1); + exit(exit_status); } int main(int argc, char **argv) @@ -465,8 +465,7 @@ int main(int argc, char **argv) optarg = arg; } if (opt == 'h' || opt == '?' || !strcmp(longopt, "help")) { - help(); - continue; + help(0); } if (opt == 'v' || !strcmp(longopt, "version")) { printf("QuickJS-ng version %s\n",JS_GetVersion()); @@ -587,12 +586,12 @@ int main(int argc, char **argv) } else { fprintf(stderr, "qjs: unknown option '--%s'\n", longopt); } - help(); + help(1); } } if (compile_file && !out) - help(); + help(1); start: From 0d9c3786d0244fe43384e420d0ea66fb07bb79f1 Mon Sep 17 00:00:00 2001 From: mhogomchungu Date: Thu, 21 May 2026 23:56:30 +0300 Subject: [PATCH 3/4] Only print version string when asked for version info --- qjs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qjs.c b/qjs.c index 66561e5f3..6419b78a4 100644 --- a/qjs.c +++ b/qjs.c @@ -468,7 +468,7 @@ int main(int argc, char **argv) help(0); } if (opt == 'v' || !strcmp(longopt, "version")) { - printf("QuickJS-ng version %s\n",JS_GetVersion()); + printf("%s\n",JS_GetVersion()); return 0; } if (opt == 'e' || !strcmp(longopt, "eval")) { From 80efe435c469f1f7595454f6fd74c8192945b7c7 Mon Sep 17 00:00:00 2001 From: mhogomchungu Date: Fri, 22 May 2026 00:02:44 +0300 Subject: [PATCH 4/4] Add documentation in the help menu on how to get version info --- qjs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/qjs.c b/qjs.c index 6419b78a4..bdf8d2d45 100644 --- a/qjs.c +++ b/qjs.c @@ -377,6 +377,7 @@ void help(int exit_status) printf("QuickJS-ng version %s\n" "usage: " PROG_NAME " [options] [file [args]]\n" "-h --help list options\n" + "-v --version print version string and then exit\n" "-e --eval EXPR evaluate EXPR\n" "-i --interactive go to interactive mode\n" "-C --script load as JS classic script (default=autodetect)\n"