Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Schniz/cmd-ts. 💻 A type-driven command line argument parser cmd-ts.now.sh
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637import { AstNode, LongOption, ShortOption } from './parser';
type Option = LongOption | ShortOption;
/** * A utility function to find an option in the AST * * @param nodes AST node list * @param opts Long and short names to look up */export function findOption( nodes: AstNode[], opts: { longNames: string[]; shortNames: string[]; }): Option[] { const result: Option[] = [];
for (const node of nodes) { if (node.type === 'longOption' && opts.longNames.includes(node.key)) { result.push(node); continue; }
if (node.type === 'shortOptions' && opts.shortNames.length) { for (const option of node.options) { if (opts.shortNames.includes(option.key)) { result.push(option); } } } }
return result;}