programming.dev
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
RSS Bot@lemmy.bestiver.se
cake
MB to Lobste.rs@lemmy.bestiver.seEnglish · 4 days ago

Stop writing CLI validation. Parse it right the first time

hackers.pub

external-link
message-square
0
link
fedilink
  • cross-posted to:
  • programming
  • [email protected]
  • typescript
  • [email protected]
2
external-link

Stop writing CLI validation. Parse it right the first time

hackers.pub

RSS Bot@lemmy.bestiver.se
cake
MB to Lobste.rs@lemmy.bestiver.seEnglish · 4 days ago
message-square
0
link
fedilink
  • cross-posted to:
  • programming
  • [email protected]
  • typescript
  • [email protected]
Stop writing CLI validation. Parse it right the first time.
hackers.pub
external-link
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.

Comments

alert-triangle
You must log in or register to comment.

Lobste.rs@lemmy.bestiver.se

lobsters@lemmy.bestiver.se

Subscribe from Remote Instance

You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: [email protected]
lock
Community locked: only moderators can create posts. You can still comment on posts.

RSS Feed of lobste.rs

Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 23 users / day
  • 109 users / week
  • 373 users / month
  • 1.23K users / 6 months
  • 11 local subscribers
  • 255 subscribers
  • 4.22K Posts
  • 232 Comments
  • Modlog
  • mods:
  • patrick@lemmy.bestiver.se
  • RSS Bot@lemmy.bestiver.se
    cake
  • BE: 0.19.11
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code
  • join-lemmy.org