diff --git a/CHANGELOG.md b/CHANGELOG.md index 82169a5..2037c22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,11 @@ The format extends [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). Version header format: `[version] Name - year-month-day (entropy-core compatibility: version [range])` +## [UNRELEASED] + +### Added +- new: option to display cli and core version + ## [0.0.4] Carnage - 2024-10-23 (entropy-core compatibility: 0.3.0) ### Added diff --git a/README.md b/README.md index 473f843..1782fa6 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,8 @@ Options: "ws://testnet.entropy.xyz:9944/", env: ENDPOINT) -h, --help display help for command + -v, --version display current cli version + -cv, --core-version display current core protocol version Commands: list|ls List all accounts. Output is JSON of form [{ name, diff --git a/package.json b/package.json index ce00866..992652a 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,8 @@ "scripts": { "start": "yarn build:global && entropy", "start:debug": "DEBUG=@entropyxyz/cli yarn start", - "build": "tsup", - "build:global": "tsup && npm install -g", + "build": "source ./node_modules/@entropyxyz/sdk/dev/bin/ENTROPY_CORE_VERSION.sh && tsup", + "build:global": "yarn build && npm install -g", "lint": "eslint . --ext .ts --fix", "test": "yarn test:types && yarn build:global && yarn test:ts && yarn test:only", "test:only": "./dev/bin/test-only.sh", diff --git a/src/cli.ts b/src/cli.ts index 16b2932..6a4e185 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -4,7 +4,7 @@ import { Command, Option } from 'commander' import { EntropyTuiOptions } from './types' -import { loadEntropy, tuiEndpointOption } from './common/utils-cli' +import { coreVersion, loadEntropy, tuiEndpointOption, versionOption } from './common/utils-cli' import * as config from './config' import launchTui from './tui' @@ -13,6 +13,7 @@ import { entropyTransferCommand } from './transfer/command' import { entropySignCommand } from './sign/command' import { entropyBalanceCommand } from './balance/command' import { entropyProgramCommand } from './program/command' +import { print } from './common/utils' const program = new Command() @@ -29,6 +30,8 @@ program .hideHelp() ) .addOption(tuiEndpointOption()) + .addOption(versionOption()) + .addOption(coreVersion()) .addCommand(entropyBalanceCommand()) .addCommand(entropyAccountCommand()) .addCommand(entropyTransferCommand()) @@ -36,10 +39,17 @@ program .addCommand(entropyProgramCommand()) .action(async (opts: EntropyTuiOptions) => { - const { account, tuiEndpoint } = opts + const { account, tuiEndpoint, version, coreVersion } = opts const entropy = account ? await loadEntropy(account, tuiEndpoint) : undefined + if (version) { + print(`v${version}`) + process.exit(0) + } else if (coreVersion) { + print(coreVersion) + process.exit(0) + } // NOTE: on initial startup you have no account launchTui(entropy, opts) }) diff --git a/src/common/ascii.ts b/src/common/ascii.ts index 67ee5f9..8fb6c6b 100644 --- a/src/common/ascii.ts +++ b/src/common/ascii.ts @@ -17,5 +17,5 @@ export const logo = @@@@@@ TEST @@@@@@ *NET @@@@@@ ENTROPY-CLI - @@@@@@ COREv0.1.0 + @@@@@@ CORE${process.env.ENTROPY_CORE_VERSION.split('-')[1]} ` diff --git a/src/common/utils-cli.ts b/src/common/utils-cli.ts index 99aaef3..d00b8b0 100644 --- a/src/common/utils-cli.ts +++ b/src/common/utils-cli.ts @@ -4,6 +4,8 @@ import { findAccountByAddressOrName, stringify } from './utils' import * as config from '../config' import { initializeEntropy } from './initializeEntropy' +const entropyPackage = require('../../package.json') + export function cliWrite (result) { const prettyResult = stringify(result, 0) process.stdout.write(prettyResult) @@ -18,6 +20,24 @@ function getConfigOrNull () { } } +export function versionOption () { + const { version } = entropyPackage + + return new Option( + '-v, --version', + 'Displays the current running version of Entropy CLI' + ).argParser(() => version) +} + +export function coreVersion () { + const coreVersion = process.env.ENTROPY_CORE_VERSION.split('-')[1] + + return new Option( + '-cv, --core-version', + 'Displays the current running version of the Entropy Protocol' + ).argParser(() => coreVersion) +} + export function endpointOption () { return new Option( '-e, --endpoint ', diff --git a/src/types/index.ts b/src/types/index.ts index 866cafb..9a912b5 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -3,6 +3,8 @@ export interface EntropyTuiOptions { endpoint: string tuiEndpoint: string dev: boolean + version: string + coreVersion: string } type EntropyLoggerLogLevel = 'error' | 'warn' | 'info' | 'debug'