From 993d469bfb8b3d973fea4aba1ad75107be1f5c73 Mon Sep 17 00:00:00 2001 From: PKulkoRaccoonGang Date: Mon, 11 Dec 2023 16:37:32 +0200 Subject: [PATCH 1/2] feat: added Paragon CLI version command --- bin/paragon-scripts.js | 11 +++++++++++ lib/version.js | 9 +++++++++ 2 files changed, 20 insertions(+) create mode 100644 lib/version.js diff --git a/bin/paragon-scripts.js b/bin/paragon-scripts.js index 6506c4dcd2..9b9628c6e1 100755 --- a/bin/paragon-scripts.js +++ b/bin/paragon-scripts.js @@ -2,8 +2,10 @@ 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 VERSION_COMMANDS = ['-v', '--version']; const COMMANDS = { /** @@ -47,12 +49,21 @@ 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]; + if (VERSION_COMMANDS.includes(command)) { + versionCommand(); + return; + } + if (!executor) { // eslint-disable-next-line no-console console.log(chalk.red.bold('Unknown command. Usage: paragon .')); 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; From acca5ac1b7c7f032428f7350d48fa74a7b1798ee Mon Sep 17 00:00:00 2001 From: PKulkoRaccoonGang Date: Wed, 13 Dec 2023 14:23:04 +0200 Subject: [PATCH 2/2] refactor: refactoring after review --- bin/paragon-scripts.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/bin/paragon-scripts.js b/bin/paragon-scripts.js index 9b9628c6e1..f192f56d9d 100755 --- a/bin/paragon-scripts.js +++ b/bin/paragon-scripts.js @@ -5,7 +5,10 @@ const helpCommand = require('../lib/help'); const versionCommand = require('../lib/version'); const HELP_COMMAND = 'help'; -const VERSION_COMMANDS = ['-v', '--version']; +const commandAliases = { + '-v': 'version', + '--version': 'version', +}; const COMMANDS = { /** @@ -57,12 +60,8 @@ const COMMANDS = { (async () => { const [command] = process.argv.slice(2); - const executor = COMMANDS[command]; - - if (VERSION_COMMANDS.includes(command)) { - versionCommand(); - return; - } + const resolvedCommand = commandAliases[command] || command; + const executor = COMMANDS[resolvedCommand]; if (!executor) { // eslint-disable-next-line no-console