From bb98f6a0c5c69efbe26715760b52880a1395068a Mon Sep 17 00:00:00 2001 From: Igor Konnov Date: Tue, 16 Apr 2024 16:31:54 +0200 Subject: [PATCH] add a simple CLI mock --- solarkraft/eslint.config.js | 7 ++++++- solarkraft/src/main.ts | 38 ++++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/solarkraft/eslint.config.js b/solarkraft/eslint.config.js index 8e7b24f..ca9eb11 100644 --- a/solarkraft/eslint.config.js +++ b/solarkraft/eslint.config.js @@ -10,4 +10,9 @@ import tseslint from 'typescript-eslint'; export default tseslint.config( eslint.configs.recommended, ...tseslint.configs.recommended, -); \ No newline at end of file + { + "rules": { + "@typescript-eslint/no-explicit-any": "off" + } + } +); diff --git a/solarkraft/src/main.ts b/solarkraft/src/main.ts index eb52a4d..1570ef7 100644 --- a/solarkraft/src/main.ts +++ b/solarkraft/src/main.ts @@ -4,8 +4,44 @@ * @license * [Apache-2.0](https://github.com/freespek/solarkraft/blob/main/LICENSE) */ + +import yargs from 'yargs' +import { version } from './version.js' + +// The default options present in every command +const defaultOpts = (yargs: any) => + yargs.option('color', { + desc: 'color output', + type: 'boolean', + default: true, + }) + +// transaction extractor +const txExtractorCmd = { + command: ['txs'], + desc: 'extract transactions', + builder: (yargs: any) => + defaultOpts(yargs) + .option('id', { + desc: 'Contract id', + type: 'string', + default: '123', + }), + handler: onTxExtractor, +} + +// call the transaction extractor here +function onTxExtractor (args: any) { + console.log(`Mock TX Extractor(id: ${args.id})`) +} + function main() { - console.log('OK') + return yargs(process.argv.slice(2)) + .command(txExtractorCmd) + .demandCommand(1) + .version(version) + .strict() + .parse() } main()