Skip to content

Commit

Permalink
feat: cli options are typed now
Browse files Browse the repository at this point in the history
  • Loading branch information
rvcas committed Mar 4, 2024
1 parent 3d3ec84 commit 62c9826
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
32 changes: 21 additions & 11 deletions cli/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'dotenv/config';
import { Command } from 'commander';
import { Command, Option } from '@commander-js/extra-typings';
import {
applyParamsToScript,
Constr,
Expand Down Expand Up @@ -41,13 +41,23 @@ const app = new Command();

app.name('fortuna').description('Fortuna miner').version('0.0.1');

const kupoUrlOption = new Option('-k, --kupo-url <string>', 'Kupo URL')
.env('KUPO_URL')
.makeOptionMandatory(true);

const ogmiosUrlOption = new Option('-o, --ogmios-url <string>', 'Ogmios URL')
.env('OGMIOS_URL')
.makeOptionMandatory(true);

const previewOption = new Option('-p, --preview', 'Use testnet').default(false);

app
.command('mine')
.description('Start the miner')
// .env('KUPO_URL=<value:string>', 'Kupo URL', { required: true })
// .env('OGMIOS_URL=<value:string>', 'Ogmios URL', { required: true })
.option('-p, --preview', 'Use testnet')
.action(async ({ preview, ogmiosUrl, kupoUrl }) => {
.addOption(kupoUrlOption)
.addOption(ogmiosUrlOption)
.addOption(previewOption)
.action(async ({ preview, kupoUrl, ogmiosUrl }) => {
while (true) {
const genesisFile = fs.readFileSync(`genesis/${preview ? 'preview' : 'mainnet'}.json`, {
encoding: 'utf8'
Expand Down Expand Up @@ -256,9 +266,9 @@ app
app
.command('genesis')
.description('Create block 0')
// .env('KUPO_URL=<value:string>', 'Kupo URL', { required: true })
// .env('OGMIOS_URL=<value:string>', 'Ogmios URL', { required: true })
.option('-p, --preview', 'Use testnet')
.addOption(kupoUrlOption)
.addOption(ogmiosUrlOption)
.addOption(previewOption)
.action(async ({ preview, ogmiosUrl, kupoUrl }) => {
const unAppliedValidator = readValidator();

Expand Down Expand Up @@ -368,9 +378,9 @@ app
app
.command('address')
.description('Check address balance')
// .env('KUPO_URL=<value:string>', 'Kupo URL', { required: true })
// .env('OGMIOS_URL=<value:string>', 'Ogmios URL', { required: true })
.option('-p, --preview', 'Use testnet')
.addOption(kupoUrlOption)
.addOption(ogmiosUrlOption)
.addOption(previewOption)
.action(async ({ preview, ogmiosUrl, kupoUrl }) => {
const provider = new Kupmios(kupoUrl, ogmiosUrl);
const lucid = await Translucent.new(provider, preview ? 'Preview' : 'Mainnet');
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"cli": "tsx cli/main.ts"
},
"devDependencies": {
"@commander-js/extra-typings": "^12.0.1",
"@playwright/test": "^1.28.1",
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/kit": "^2.0.0",
Expand Down
11 changes: 11 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 62c9826

Please sign in to comment.