showRoutes function
Prints all registered routes to stdout.
verbose: appends the number of per-route middlewares when > 0colorize: wraps HTTP method labels in ANSI colour codes
final app = Darto().basePath('/v1');
app.get('/posts', handler);
app.get('/posts/:id', handler);
app.post('/posts', handler);
showRoutes(app, colorize: true);
// GET /v1/posts
// GET /v1/posts/:id
// POST /v1/posts
Implementation
void showRoutes(
Darto app, {
bool verbose = false,
bool colorize = false,
}) {
final entries = app.routeEntries;
if (entries.isEmpty) {
stdout.writeln('No routes registered.');
return;
}
for (final e in entries) {
// Pad the raw method first, then wrap in colour so ANSI codes don't
// distort the visual alignment.
final padded = e.method.padRight(7);
final label =
colorize ? '$_bold${_methodColor(e.method)}$padded$_reset' : padded;
final mwSuffix = (verbose && e.middlewareCount > 0)
? (colorize
? ' $_dim[${e.middlewareCount} mw]$_reset'
: ' [${e.middlewareCount} mw]')
: '';
stdout.writeln('$label ${e.path}$mwSuffix');
}
}