@fairdatasociety/fdp-cli
Version:
CLI tool for FDP-Storage
45 lines (32 loc) • 1.31 kB
text/typescript
import { Argument, LeafCommand } from 'furious-commander'
import { Message } from '../../utils/message'
import { getMainPod, setMainPod } from '../../utils/config'
import { PodCommand } from './pod-command'
import { getAllPods } from '../../../test/utility/fdp'
export class Main extends PodCommand implements LeafCommand {
public readonly name = 'main'
public readonly description = 'Set or show main pod'
public podName!: string
public async run(): Promise<void> {
await super.init()
const account = this.getCurrentAccountName(this.account)
if (!this.podName) {
const mainPod = getMainPod(account, this.commandConfig.config)
if (mainPod) {
this.console.log(Message.mainPod(mainPod))
} else {
this.console.log(Message.mainPodEmpty())
}
return
}
const pods = await this.fdpStorage.personalStorage.list()
const allPods = getAllPods(pods)
if (!allPods.find(item => item.name === this.podName)) {
this.console.log(Message.podNotFound(this.podName))
return
}
setMainPod(account, this.podName, this.commandConfig.configFilePath, this.commandConfig.config)
this.console.log(Message.newMainPod(this.podName))
}
}