▲ 109 ▼ Stop writing CLI validation. Parse it right the first time. (hackers.pub) submitted 11 months ago by hongminhee@lemmy.ml to c/programming@programming.dev 18 comments fedilink hide all child comments
[–] verstra@programming.dev 11 points 11 months ago (1 child) clap already supports all this: https://docs.rs/clap/latest/clap/struct.Arg.html#method.conflicts_with It's just a great library, having you could think of and applying the same parse-don't-validate mentality. permalink fedilink source parent hideshow 2 child comments replies: [–] TehPers@beehaw.org 9 points 11 months ago (1 child) This doesn't represent the mutual exclusivity through the type system (which is what the article is all about). I love clap and I use it a lot, but the only way to represent the exclusivity through the type system in Rust is through an enum. permalink fedilink source parent hideshow 2 child comments replies: [–] ExFed@programming.dev 5 points 11 months ago Agreed. As nice as clap is, it's not a combinator. Parser combinators have a the really nice feature of sharing the same "shape" as the data they parse, which makes them trivial to generate from a schema ... or to just use them to represent your schema in the first place ;) . permalink fedilink source parent
[–] TehPers@beehaw.org 9 points 11 months ago (1 child) This doesn't represent the mutual exclusivity through the type system (which is what the article is all about). I love clap and I use it a lot, but the only way to represent the exclusivity through the type system in Rust is through an enum. permalink fedilink source parent hideshow 2 child comments replies: [–] ExFed@programming.dev 5 points 11 months ago Agreed. As nice as clap is, it's not a combinator. Parser combinators have a the really nice feature of sharing the same "shape" as the data they parse, which makes them trivial to generate from a schema ... or to just use them to represent your schema in the first place ;) . permalink fedilink source parent
[–] ExFed@programming.dev 5 points 11 months ago Agreed. As nice as clap is, it's not a combinator. Parser combinators have a the really nice feature of sharing the same "shape" as the data they parse, which makes them trivial to generate from a schema ... or to just use them to represent your schema in the first place ;) . permalink fedilink source parent