Stop writing CLI validation. Parse it right the first time

29 dahlia 10 9/6/2025, 6:20:26 PM hackers.pub ↗

Comments (10)

jmull · 4m ago
> Think about it. When you get JSON from an API, you don't just parse it as any and then write a bunch of if-statements. You use something like Zod to parse it directly into the shape you want. Invalid data? The parser rejects it. Done.

Isn’t writing code and using zod the same thing? The difference being who wrote the code.

Of course, you hope zod is robust, tested, supported, extensible, and has docs so you can understand how to express your domain in terms it can help you with. And you hope you don’t have to spend too much time migrating as zod’s api changes.

dvdkon · 32m ago
I, for one, do think the world needs more CLI argument parsers :)

This project looks neat, I've never thought to use parser combinators for something other than left-to-right string/token stream parsing.

And I like how it uses Typescript's metaprogramming to generate types from the parser code. I think that would be much harder (or impossible) in other languages, making the idiomatic design of a similar similar library very different.

thealistra · 30m ago
Isn’t this like argparse from Python for typescript?
yakshaving_jgt · 33m ago
I've noticed that many programmers believe that parsing is some niche thing that the average programmer likely won't need to contend with, and that it's only applicable in a few specific low-level cases, in which you'll need to reach for a parser combinator library, etc.

But this is wrong. Programmers should be writing parsers all the time!

dkubb · 57s ago
The three most common things I think about when coding are DAGs, State Machines and parsing. The latter two come up all the time in regexps which I probably write at least once a day, and I’m always thinking about state transitions and dependencies.
WJW · 11m ago
Last week my primary task was writing a github action that needed to log in to Heroku and push the current code on main and development branches to the production and staging environments respectively. The week before that, I wrote some code to make sure the type the object was included in the filters passed to an API call.

Don't get me wrong, I actually love writing parsers. It's just not required all that often in my day-to-day work. 99% of the time when I need to write a parser myself it's for and Advent of Code problem, usually I just import whatever JSON or YAML parser is provided for the platform and go from there.

yakshaving_jgt · 1m ago
Do you not write validation? Or handle user input? Or handle server responses? Surely there’s some data processing somewhere.
HL33tibCe7 · 31m ago
Stopped reading after realising this is written by ChatGPT
bfung · 22m ago
Looked human-ish to me, what signs did you see?
cazum · 16m ago
What makes you think that and not that it's just an average auto-translate job from the author's native language (Korean)?