Skip to content

Commit

Permalink
multi-command cli for dev tools
Browse files Browse the repository at this point in the history
  • Loading branch information
mfornos committed Jun 30, 2023
1 parent 096d58e commit 81eb44f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
8 changes: 7 additions & 1 deletion tools/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Development Support Tools

TBD

```
yarn octools -h
```

## Capture

The capture tool is a command line tool that allows you to download blocks from a network, enhance them as extended signed blocks, and output a CBOR representation.
Expand All @@ -9,6 +15,6 @@ This tool is useful for capturing blockchain data to be used in tests.
To use the capture tool, run the following command:

```shell
./capture.ts ./out.cbor --start="2841323" --count="20" --url="wss://rococo-contracts-rpc.polkadot.io"
yarn octools capture ./out.cbor --start="2841323" --count="20" --url="wss://rococo-contracts-rpc.polkadot.io"
```
In the above example, it downloads 20 blocks from the Rococo Contracts network and saves the enhanced blocks in the `out.cbor` file.
9 changes: 7 additions & 2 deletions tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@
"url": "https://github.com/sodazone/ocelloids.git"
},
"bin": {
"capture": "src/capture.ts",
"cdump": "src/cdump.ts"
"octools": "lib/main.cjs"
},
"dependencies": {
"@sodazone/ocelloids": "1.0.0-dev.0",
"@sodazone/ocelloids-test": "1.0.0-dev.0",
"cbor-x": "^1.5.3",
"citty": "^0.1.1"
},
"tsup": {
"shims": true
},
"scripts": {
"build": "tsup src/main.ts --clean --minify -d lib/"
},
"stableVersion": "1.0.0"
}
7 changes: 2 additions & 5 deletions tools/src/capture.ts → tools/src/commands/capture.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env ts-node-esm
/*
* Copyright 2023 SO/DA zone - Marc Fornós & Xueying Wang
*
Expand All @@ -20,7 +19,7 @@ import { writeFileSync } from 'node:fs';
import { Observer } from 'rxjs';
import { encode } from 'cbor-x';

import { defineCommand, runMain } from 'citty';
import { defineCommand } from 'citty';

import { WsProvider } from '@polkadot/api';
import { SignedBlockExtended } from '@polkadot/api-derive/types';
Expand Down Expand Up @@ -78,7 +77,7 @@ function downloadBlocks({
);
}

const main = defineCommand({
export default defineCommand({
meta: {
name: 'capture',
version: '0.0.1',
Expand Down Expand Up @@ -107,5 +106,3 @@ const main = defineCommand({
downloadBlocks(args);
},
});

runMain(main as any);
17 changes: 17 additions & 0 deletions tools/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env node

import { defineCommand, runMain } from 'citty';
import capture from './commands/capture.js';

const main = defineCommand({
meta: {
name: 'octools',
version: '1.0.0',
description: 'Ocelloids development support tools',
},
subCommands: {
capture,
},
});

runMain(main);
3 changes: 1 addition & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1556,8 +1556,7 @@ __metadata:
cbor-x: ^1.5.3
citty: ^0.1.1
bin:
capture: src/capture.ts
cdump: src/cdump.ts
octools: lib/main.cjs
languageName: unknown
linkType: soft

Expand Down

0 comments on commit 81eb44f

Please sign in to comment.