Expose auth repos in context; create routes commands
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
33
src/cli/directive/RoutesDirective.ts
Normal file
33
src/cli/directive/RoutesDirective.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import {Directive} from '../Directive'
|
||||
import {Inject, Injectable} from '../../di'
|
||||
import {Routing} from '../../service/Routing'
|
||||
import Table = require('cli-table')
|
||||
|
||||
@Injectable()
|
||||
export class RoutesDirective extends Directive {
|
||||
@Inject()
|
||||
protected readonly routing!: Routing
|
||||
|
||||
getDescription(): string {
|
||||
return 'List routes registered in the application'
|
||||
}
|
||||
|
||||
getKeywords(): string | string[] {
|
||||
return ['routes']
|
||||
}
|
||||
|
||||
async handle(): Promise<void> {
|
||||
const maxRouteLength = this.routing.getCompiled().max(route => String(route).length)
|
||||
const maxHandlerLength = this.routing.getCompiled().max(route => route.getDisplayableHandler().length)
|
||||
const rows = this.routing.getCompiled().map<[string, string]>(route => [String(route), route.getDisplayableHandler()])
|
||||
|
||||
const table = new Table({
|
||||
head: ['Route', 'Handler'],
|
||||
colWidths: [maxRouteLength + 2, maxHandlerLength + 2],
|
||||
})
|
||||
|
||||
table.push(...rows.toArray())
|
||||
|
||||
this.info('\n' + table)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user