@ethersphere/swarm-cli
Version:
CLI tool for Bee
41 lines (34 loc) • 1.35 kB
text/typescript
import fs from 'fs'
import { Argument, LeafCommand, Option } from 'furious-commander'
import { stampProperties } from '../../utils/option'
import { createKeyValue } from '../../utils/text'
import { GranteeCommand } from './grantee-command'
export class Create extends GranteeCommand implements LeafCommand {
public readonly name = 'create'
public readonly description = 'Create grantee list'
private actReqHeaders: Record<string, string> = {}
({
key: 'path',
description: 'Path to the file with grantee list',
required: true,
autocompletePath: true,
conflicts: 'stdin',
})
public path!: string
({ key: 'stdin', type: 'boolean', description: 'Take data from standard input', conflicts: 'path' })
public stdin!: boolean
(stampProperties)
public stamp!: string
public async run(): Promise<void> {
super.init()
this.actReqHeaders = {
'Swarm-Act': 'true',
}
const granteesFile = fs.readFileSync(this.path, 'utf8')
const createGrantees = JSON.parse(granteesFile)
const grantees = createGrantees.grantees
const response = await this.bee.createGrantees(this.stamp, grantees)
this.console.log(createKeyValue('Grantee reference', response.ref.toHex()))
this.console.log(createKeyValue('Grantee history reference', response.historyref.toHex()))
}
}