diff --git a/src/lib/options.ts b/src/lib/options.ts new file mode 100644 index 0000000..3568f9d --- /dev/null +++ b/src/lib/options.ts @@ -0,0 +1,33 @@ +import { AsText, TextPiece } from '../words'; + +type SwitchPattern = Record & { + min?: number; + max?: number; +}; +type SwitchOutput

= { + [K in keyof P]: K extends "min" | "max" + ? never + : P[K] extends 0 + ? boolean + : string[]; +} & { + error?: string; +}; + +// TODO: tests and error handling +export function getOpt

( + argv: TextPiece[], + switches: P +): [SwitchOutput

, ...string[]] { + const [flags, textPieces] = getOptRaw(argv, switches); + return [flags, ...textPieces.map(AsText)]; +} + +export function getOptRaw

( + argv: TextPiece[], + switches: P +): [SwitchOutput

, TextPiece[]] { + const [, ...words] = argv; + // TODO: handle min/max + return [{} as SwitchOutput

, words]; +}