Stop writing if statements for your CLI flags

Stop writing if statements for your CLI flags洪 民憙 (Hong Minhee) @hongminhee@hackers.pub12/10/2025, 3:42:02 AM If you’ve built CLI tools, you’ve written code like this: if (opts.reporter === “junit” && !opts.outputFile) { throw new Error(“–output-file is required for junit reporter”); } if (opts.reporter === “html” && !opts.outputFile) { throw new Error(“–output-file is required for html reporter”); } if (opts.reporter === “console” && opts.outputFile) { console.warn(“–output-file is ignored for console reporter”); } A few months ago, I wrote Stop writing CLI validation. Parse it right the first time. about parsing individual option values correctly. But it didn’t cover the relationships between options. In the code above, –output-file only makes sense…

Read more on Lobste.rs