-
Notifications
You must be signed in to change notification settings - Fork 115
/
threads.ts
38 lines (34 loc) · 1.2 KB
/
threads.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { flags } from '@oclif/command'
import chalk from 'chalk'
import ForumCommandBase from '../../base/ForumCommandBase'
import { displayTable } from '../../helpers/display'
import { formatBalance } from '@polkadot/util'
export default class ForumThreadsCommand extends ForumCommandBase {
static description = 'List existing forum threads in given category.'
static flags = {
categoryId: flags.integer({
char: 'c',
required: true,
description: 'Category id (only threads in this category will be listed)',
}),
...ForumCommandBase.flags,
}
async run(): Promise<void> {
const { categoryId } = this.parse(ForumThreadsCommand).flags
await this.ensureCategoryExists(categoryId)
const threads = await this.getApi().forumThreads(categoryId)
if (threads.length) {
displayTable(
threads.map(([id, t]) => ({
'ID': id.toString(),
'Cleanup payoff': formatBalance(t.cleanupPayOff.amount),
'Author member id': t.authorId.toString(),
'No. editable posts': t.numberOfEditablePosts.toString(),
})),
5
)
} else {
this.log(`No threads in category ${chalk.magentaBright(categoryId)} found`)
}
}
}