Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Commit

Permalink
feat(cli): purge parameter for start command
Browse files Browse the repository at this point in the history
  • Loading branch information
AuHau committed Apr 23, 2020
1 parent 53e2a61 commit 81919f9
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/cli/start.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import config from 'config'
import { flags } from '@oclif/command'

import { appFactory, isSupportedServices, SupportedServices } from '../app'
import { appFactory, isSupportedServices, services, SupportedServices } from '../app'
import { loggingFactory } from '../logger'
import { Flags, Config } from '../types'
import { BaseCLICommand } from '../utils'
Expand All @@ -24,11 +24,15 @@ ${formattedServices}`
port: flags.integer({ char: 'p', description: 'port to attach the server to' }),
db: flags.string({ description: 'database connection URI', env: 'RIFM_DB' }),
provider: flags.string({ description: 'blockchain provider connection URI', env: 'RIFM_PROVIDER' }),
purge: flags.boolean({
char: 'u',
description: 'will purge services that should be lunched (eq. enable/disable is applied)'
}),
enable: flags.string({ char: 'e', multiple: true, description: 'enable specific service' }),
disable: flags.string({ char: 'd', multiple: true, description: 'disable specific service' })
}

buildConfigObject (flags: Flags<typeof StartServer>): object {
private buildConfigObject (flags: Flags<typeof StartServer>): object {
const output: Config = {}

if (flags.db) {
Expand Down Expand Up @@ -78,16 +82,31 @@ ${formattedServices}`
return output
}

private async purge (): Promise<void> {
const toBePurgedServices = (Object.keys(services) as Array<keyof typeof services>)
.filter(service => config.get<boolean>(`${service}.enabled`))

logger.info(`Purging services: ${toBePurgedServices.join(', ')}`)

await Promise.all(
toBePurgedServices.map((service) => services[service].purge())
)
}

// TODO: DB connnection setting
// TODO: Provider connection setting
run (): Promise<void> {
async run (): Promise<void> {
const { flags } = this.parse(StartServer)

const configOverrides = this.buildConfigObject(flags)
config.util.extendDeep(config, configOverrides)

const app = appFactory()

if (flags.purge) {
await this.purge()
}

const port = config.get('port')
const server = app.listen(port)

Expand Down

0 comments on commit 81919f9

Please sign in to comment.