suggest
The commands closest to a mistyped one (or starting with it).
import { routes } from "#codebase/tcmts/cli/commands"; import { distance } from "#codebase/tcmts/cli/help"; export function suggest(word: string): string[] { const scored = Object.keys(routes()).map( (c) => [c, c.startsWith(word) ? 0 : distance(word, c)] as const, ); const best = Math.min(...scored.map(([, d]) => d)); return best <= Math.max(1, Math.floor(word.length / 3)) ? scored.filter(([, d]) => d === best).map(([c]) => c) : []; }