Skip to content

Commit 8df55a0

Browse files
committed
feat: added --version parameter
1 parent 8f304ce commit 8df55a0

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/index.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const fs = require("fs-extra");
44
const ejs = require("ejs");
5+
const packageJson = require("../package.json");
56

67
// biome-ignore lint/style/useNodejsImportProtocol: The node: protocol doesn't work on NodeJS v10 and v12, so it's not added to make the compatibility possible.
78
const os = require("os");
@@ -313,11 +314,16 @@ function processParameter(arg, args, index) {
313314
} else if (
314315
args[index + 1] &&
315316
!args[index + 1].startsWith("--") &&
316-
argumentName !== "help"
317+
argumentName !== "help" &&
318+
argumentName !== "version"
317319
) {
318320
param = argumentName;
319321
value = args[index + 1];
320-
} else if (argumentName !== "help" && argumentName !== "open") {
322+
} else if (
323+
argumentName !== "help" &&
324+
argumentName !== "version" &&
325+
argumentName !== "open"
326+
) {
321327
console.error(`Error: Missing value for parameter '${argumentName}'.`);
322328
process.exit(1);
323329
} else {
@@ -333,7 +339,10 @@ function processParameter(arg, args, index) {
333339
OPTIONS.open = true;
334340
break;
335341
case "help":
336-
showHelp();
342+
showMessageAndExit(HELP_TEXT);
343+
break;
344+
case "version":
345+
showMessageAndExit(`v${packageJson.version}`);
337346
break;
338347
default:
339348
console.error(`Error: Unknown parameter '${param}'.`);
@@ -359,8 +368,8 @@ function handleParameter(param, value) {
359368
/**
360369
* Displays the help text and exits the script with a success status code.
361370
*/
362-
function showHelp() {
363-
console.log(HELP_TEXT);
371+
function showMessageAndExit(msg) {
372+
console.log(msg);
364373
process.exit(0);
365374
}
366375

0 commit comments

Comments
 (0)