ryanmiville / clad

Command line argument decoders for Gleam
0 stars 2 forks source link

Support positional arguments #2

Open GearsDatapacks opened 1 week ago

GearsDatapacks commented 1 week ago

For example:

use name <- clad.positional(dynamic.string)
use age <- clad.positional(dynamic.int)
use is_alive <- clag.toggle(long_name: "alive", short_name: "a")
clad.decoded(Person(name:, age:, is_alive:))

This would parse program <name> <age> [-a|--alive]

Default positional arguments don't make much sense, because if you omit one, the whole chain breaks.

ryanmiville commented 23 hours ago

Yeah this definitely on my todo list. I'm still not settled on an API, though it's probably pretty close to where it will end up. I want to get that locked down before working on anything else.

The current implementation for encoding is pretty limited in scope and will get rewritten. Right now, all positional information is lost as the args are encoded as a dictionary. Positional arguments aren't really possible before a rewrite.

You can also give clip a try. It has more features and seems to have more momentum behind it at the moment. It's goals do not entirely align with mine for clad. A main goal for clad is to feel the same as writing a normal decoder. I'm currently hedging my bets that toy will "win", and something similar will be added to the standard lib, so I'm trying to align with it.