Jellie Frontier
  • Communities
  • Create Post
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
洪 民憙 (Hong Minhee)@lemmy.ml to Programming@programming.devEnglish · 7 days ago

Stop writing CLI validation. Parse it right the first time.

hackers.pub

external-link
message-square
10
fedilink
69
external-link

Stop writing CLI validation. Parse it right the first time.

hackers.pub

洪 民憙 (Hong Minhee)@lemmy.ml to Programming@programming.devEnglish · 7 days ago
message-square
10
fedilink
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.
  • thingsiplay@beehaw.org
    link
    fedilink
    arrow-up
    12
    arrow-down
    1
    ·
    edit-2
    7 days ago

    https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/ - Edit: Ah I see, the author of this article is pointing to this older article too and admits being influenced by it. So never mind.

Programming@programming.dev

programming@programming.dev

Subscribe from Remote Instance

Create a post
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: !programming@programming.dev

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person’s post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you’re posting long videos try to add in some form of tldr for those who don’t want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



Visibility: Public
globe

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

  • 56 users / day
  • 255 users / week
  • 1.22K users / month
  • 4.39K users / 6 months
  • 1 local subscriber
  • 22.6K subscribers
  • 630 Posts
  • 3.75K Comments
  • Modlog
  • mods:
  • snowe@programming.dev
  • Ategon@programming.dev
  • MaungaHikoi@lemmy.nz
  • UlrikHD@programming.dev
  • BE: 0.19.8
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org