Stop writing CLI validation. Parse it right the first time
4 days ago
- #TypeScript
- #Parsing
- #CLI
- Hong Minhee built Optique to eliminate repetitive CLI validation code.
- Traditional CLI validation involves parsing data first and then checking validity, which is inefficient.
- Optique uses parser combinators to parse CLI arguments directly into valid types, eliminating the need for separate validation.
- Three common CLI validation patterns addressed by Optique: dependent options, mutually exclusive options, and environment-specific requirements.
- Optique leverages TypeScript's type inference to automatically ensure correct CLI configurations without manual type definitions.
- Using Optique reduces code, simplifies refactoring, and increases trust in CLI tools by catching errors at compile time.
- Optique is suitable for complex CLI tools but may be overkill for simple scripts.
- The library is still evolving, but the core principle of 'parse, don't validate' is robust and effective.