verify-bag-id.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { flags } from '@oclif/command'
  2. import ApiCommandBase from '../../command-base/ApiCommandBase'
  3. import { parseBagId } from '../../services/helpers/bagTypes'
  4. import logger from '../../services/logger'
  5. /**
  6. * CLI command:
  7. * Verifies supported bag ID types in the string format.
  8. *
  9. * @remarks
  10. * Should be run only during the development.
  11. * Shell command: "dev:verify-bag-id"
  12. */
  13. export default class DevVerifyBagId extends ApiCommandBase {
  14. static description = 'The command verifies bag id supported by the storage node. Requires chain connection.'
  15. static flags = {
  16. bagId: flags.string({
  17. char: 'i',
  18. required: true,
  19. description: `
  20. Bag ID. Format: {bag_type}:{sub_type}:{id}.
  21. - Bag types: 'static', 'dynamic'
  22. - Sub types: 'static:council', 'static:wg', 'dynamic:member', 'dynamic:channel'
  23. - Id:
  24. - absent for 'static:council'
  25. - working group name for 'static:wg'
  26. - integer for 'dynamic:member' and 'dynamic:channel'
  27. Examples:
  28. - static:council
  29. - static:wg:storage
  30. - dynamic:member:4
  31. `,
  32. }),
  33. ...ApiCommandBase.flags,
  34. }
  35. async run(): Promise<void> {
  36. const { flags } = this.parse(DevVerifyBagId)
  37. const api = await this.getApi()
  38. const parsedBagId = parseBagId(api, flags.bagId)
  39. logger.info(`Correct bag id: ${flags.bagId}`)
  40. logger.info(`Parsed: ${parsedBagId}`)
  41. }
  42. }