threads.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { flags } from '@oclif/command'
  2. import chalk from 'chalk'
  3. import ForumCommandBase from '../../base/ForumCommandBase'
  4. import { displayTable } from '../../helpers/display'
  5. import { formatBalance } from '@polkadot/util'
  6. export default class ForumThreadsCommand extends ForumCommandBase {
  7. static description = 'List existing forum threads in given category.'
  8. static flags = {
  9. categoryId: flags.integer({
  10. char: 'c',
  11. required: true,
  12. description: 'Category id (only threads in this category will be listed)',
  13. }),
  14. ...ForumCommandBase.flags,
  15. }
  16. async run(): Promise<void> {
  17. const { categoryId } = this.parse(ForumThreadsCommand).flags
  18. await this.ensureCategoryExists(categoryId)
  19. const threads = await this.getApi().forumThreads(categoryId)
  20. if (threads.length) {
  21. displayTable(
  22. threads.map(([id, t]) => ({
  23. 'ID': id.toString(),
  24. 'Cleanup payoff': formatBalance(t.cleanup_pay_off),
  25. 'Author member id': t.author_id.toString(),
  26. 'No. posts': t.number_of_posts.toString(),
  27. })),
  28. 5
  29. )
  30. } else {
  31. this.log(`No threads in category ${chalk.magentaBright(categoryId)} found`)
  32. }
  33. }
  34. }