Skip to content

Commit

Permalink
[NayNay] Entropy Version
Browse files Browse the repository at this point in the history
- added option to display versions
  • Loading branch information
rh0delta committed Oct 24, 2024
1 parent d8d0b33 commit 2441d07
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 12 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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()

Expand All @@ -29,17 +30,26 @@ program
.hideHelp()
)
.addOption(tuiEndpointOption())
.addOption(versionOption())
.addOption(coreVersion())
.addCommand(entropyBalanceCommand())
.addCommand(entropyAccountCommand())
.addCommand(entropyTransferCommand())
.addCommand(entropySignCommand())
.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)
})
Expand Down
2 changes: 1 addition & 1 deletion src/common/ascii.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ export const logo =
@@@@@@ TEST
@@@@@@ *NET
@@@@@@ ENTROPY-CLI
@@@@@@ COREv0.1.0
@@@@@@ CORE${process.env.ENTROPY_CORE_VERSION.split('-')[1]}
`
20 changes: 20 additions & 0 deletions src/common/utils-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 <url>',
Expand Down
2 changes: 2 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export interface EntropyTuiOptions {
endpoint: string
tuiEndpoint: string
dev: boolean
version: string
coreVersion: string
}

type EntropyLoggerLogLevel = 'error' | 'warn' | 'info' | 'debug'
Expand Down

0 comments on commit 2441d07

Please sign in to comment.