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.
12345678910111213141516171819202122import { inspect } from "node:util";import type { Type } from "./type";
/** * A union of literals. When you want to take an exact enum value. */export function oneOf<T extends string>( literals: readonly T[],): Type<string, T> { const examples = literals.map((x) => inspect(x)).join(", "); return { async from(str) { const value = literals.find((x) => x === str); if (!value) { throw new Error(`Invalid value '${str}'. Expected one of: ${examples}`); } return value; }, description: `One of ${examples}`, };}