@ethersphere/swarm-cli
Version:
CLI tool for Bee
42 lines (33 loc) • 1.49 kB
text/typescript
import { MantarayNode } from '@ethersphere/bee-js'
import { Optional } from 'cafe-utility'
import { Argument, LeafCommand, Option } from 'furious-commander'
import { pickStamp } from '../../service/stamp'
import { stampProperties } from '../../utils/option'
import { RootCommand } from '../root-command'
export class Merge extends RootCommand implements LeafCommand {
public readonly name = 'merge'
public readonly description = 'Merge two manifests'
public destination!: string
public source!: string
public stamp!: string
public async run(): Promise<void> {
super.init()
if (!this.stamp) {
this.stamp = await pickStamp(this.bee, this.console)
}
const destinationNode = await MantarayNode.unmarshal(this.bee, this.destination)
const sourceNode = await MantarayNode.unmarshal(this.bee, this.source)
await sourceNode.loadRecursively(this.bee)
await destinationNode.loadRecursively(this.bee)
const nodes = sourceNode.collect()
for (const node of nodes) {
destinationNode.addFork(node.fullPathString, node.targetAddress, node.metadata)
}
const root = await destinationNode.saveRecursively(this.bee, this.stamp)
this.console.log(root.reference.toHex())
this.result = Optional.of(root.reference)
}
}