@fairdatasociety/fdp-cli
Version:
CLI tool for FDP-Storage
41 lines (34 loc) • 1.24 kB
text/typescript
import { Argument, LeafCommand } from 'furious-commander'
import { Message } from '../../utils/message'
import { FileCommand } from './file-command'
import { expectFilePathAvailable, getString, saveData } from '../../utils'
export class Download extends FileCommand implements LeafCommand {
public readonly name = 'download'
public readonly description = 'Download a file'
public pathSource!: string
public pathDestination!: string
public async run(): Promise<void> {
await super.init()
try {
expectFilePathAvailable(this.pathDestination)
const data = await this.fdpStorage.file.downloadData(
await this.getCurrentPodName(this.account, this.pod),
this.pathSource,
)
saveData(this.pathDestination, data)
this.console.log(Message.fileDownloadedSuccessfully(this.pathSource, this.pathDestination))
} catch (error: unknown) {
this.console.log(Message.fileDownloadError(getString(error, 'message')))
}
}
}