From dbf2568b3bec75332f36ceb5eaa40cc2901fa926 Mon Sep 17 00:00:00 2001 From: Peter Kulko <93188219+PKulkoRaccoonGang@users.noreply.github.com> Date: Wed, 13 Dec 2023 16:32:45 +0200 Subject: [PATCH] feat: added Paragon CLI version command (#2921) * feat: added Paragon CLI version command * refactor: refactoring after review --- bin/paragon-scripts.js | 12 +++++++++++- lib/version.js | 9 +++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 lib/version.js diff --git a/bin/paragon-scripts.js b/bin/paragon-scripts.js index 6506c4dcd2..f192f56d9d 100755 --- a/bin/paragon-scripts.js +++ b/bin/paragon-scripts.js @@ -2,8 +2,13 @@ const chalk = require('chalk'); const themeCommand = require('../lib/install-theme'); const helpCommand = require('../lib/help'); +const versionCommand = require('../lib/version'); const HELP_COMMAND = 'help'; +const commandAliases = { + '-v': 'version', + '--version': 'version', +}; const COMMANDS = { /** @@ -47,11 +52,16 @@ const COMMANDS = { executor: helpCommand, description: 'Displays help for available commands.', }, + version: { + executor: versionCommand, + description: 'Displays the current version of Paragon CLI.', + }, }; (async () => { const [command] = process.argv.slice(2); - const executor = COMMANDS[command]; + const resolvedCommand = commandAliases[command] || command; + const executor = COMMANDS[resolvedCommand]; if (!executor) { // eslint-disable-next-line no-console diff --git a/lib/version.js b/lib/version.js new file mode 100644 index 0000000000..b1adabd67f --- /dev/null +++ b/lib/version.js @@ -0,0 +1,9 @@ +/* eslint-disable no-console */ +const chalk = require('chalk'); +const { version } = require('../package.json'); + +function versionCommand() { + console.log(`Paragon CLI version: ${chalk.bold(version)}`); +} + +module.exports = versionCommand;