Get the latest tech news

Stop writing CLI validation. Parse it right the first time


This post introduces Optique, a new library created to address the pervasive problem of repetitive and often messy validation code in CLI tools. The author was motivated by the observation that nearly every CLI tool reinvents the wheel with similar validation patterns for dependent options, mutually exclusive options, and environment-specific requirements. Optique leverages parser combinators and TypeScript's type inference to ensure that CLI arguments are parsed directly into valid configurations, eliminating the need for manual validation. By describing the desired CLI configuration with Optique, TypeScript automatically infers the types and constraints, catching potential bugs at compile time. The author shares their experience of deleting large chunks of validation code and simplifying refactoring tasks. Optique aims to provide a more robust and maintainable approach to CLI argument parsing, potentially saving developers from writing the same validation logic repeatedly.

Open source projects, work stuff, random GitHub repos I stumble upon at 2 AM. The type system now understands that when server is false, port literally doesn't exist. You change the parser definition, TypeScript immediately shows you every place that breaks, you fix them, done.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Time

Time

Photo of CLI

CLI

Photo of CLI validation

CLI validation

Related news:

News photo

Show HN: Greppers – fast CLI cheat sheet with instant copy and shareable search

News photo

Nick Bostrom: 'People will look back on 2025 and shudder in horror'. Silicon valley’s favourite philosopher has dire warnings about the race artificial general intelligence. Is there still time for the tech bros to listen?

News photo

Roborock's new weed-killing robot mowers will save your back (and time)