You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.2 KiB
42 lines
1.2 KiB
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 compiled = this.routing.getCompiled()
|
|
|
|
const maxRouteLength = compiled.strings().max('length')
|
|
const maxHandlerLength = compiled.mapCall('getHandlerDisplay')
|
|
.whereDefined()
|
|
.max('length')
|
|
const maxNameLength = compiled.mapCall('getAlias')
|
|
.whereDefined()
|
|
.max('length')
|
|
|
|
const rows = compiled.map(route => [String(route), route.getHandlerDisplay(), route.getAlias() || ''])
|
|
|
|
const table = new Table({
|
|
head: ['Route', 'Handler', 'Name'],
|
|
colWidths: [maxRouteLength + 2, maxHandlerLength + 2, maxNameLength + 2],
|
|
})
|
|
|
|
table.push(...rows.toArray())
|
|
|
|
this.info('\n' + table)
|
|
}
|
|
}
|