Skip to content

Commit 738ae88

Browse files
authored
feat: add cid command (#579)
1 parent cf65d19 commit 738ae88

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/command/utility/cid.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Reference } from '@ethersphere/bee-js'
2+
import { Argument, LeafCommand } from 'furious-commander'
3+
import { createKeyValue } from '../../utils/text'
4+
import { RootCommand } from '../root-command'
5+
6+
export class Cid extends RootCommand implements LeafCommand {
7+
public readonly name = 'cid'
8+
9+
public readonly description = 'Convert to or from a CID'
10+
11+
@Argument({
12+
key: 'value',
13+
description: 'CID or reference',
14+
required: true,
15+
})
16+
public value!: string
17+
18+
public async run(): Promise<void> {
19+
super.init()
20+
21+
const reference = new Reference(this.value)
22+
this.console.all(createKeyValue('CID (feed)', reference.toCid('feed')))
23+
this.console.all(createKeyValue('CID (manifest)', reference.toCid('manifest')))
24+
this.console.all(createKeyValue('Reference', reference.toHex()))
25+
}
26+
}

src/command/utility/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { readFile } from 'fs/promises'
33
import { GroupCommand } from 'furious-commander'
44
import { fileExists } from '../../utils'
55
import { CommandLog } from '../root-command/command-log'
6+
import { Cid } from './cid'
67
import { GetBee } from './get-bee'
78
import { Lock } from './lock'
89
import { Redeem } from './redeem'
@@ -13,7 +14,7 @@ export class Utility implements GroupCommand {
1314

1415
public readonly description = 'Utility commands related to Swarm and wallets'
1516

16-
public subCommandClasses = [Lock, Unlock, GetBee, Redeem]
17+
public subCommandClasses = [Cid, Lock, Unlock, GetBee, Redeem]
1718
}
1819

1920
export async function createWallet(pathOrPrivateKey: string, console: CommandLog): Promise<Wallet> {

0 commit comments

Comments
 (0)