TanklesXL / glint

Gleam command-line argument parsing with flags and automated help text generation.
https://hex.pm/packages/glint
Apache License 2.0
50 stars 7 forks source link

#11 #13 Constraints & optional default flag values #14

Closed TanklesXL closed 1 year ago

TanklesXL commented 1 year ago

11 : this change includes the additions of a Constraint type for adding flag value checks to glint, this is consistent with keeping glint itself non-generic while adding a nicely extensible validation functionality

TanklesXL commented 1 year ago

13: since i'm already changing the signature of the flag creation functions i switched to an Option for the default flag value, this way if a flag is required but not provided an error will be returned

TanklesXL commented 1 year ago

one open question, is it better to have the getters return an Error if the flag has no default and is requested, or should they just return an Option and let the caller decide what that should mean

tim2CF commented 1 year ago

one open question, is it better to have the getters return an Error if the flag has no default and is requested, or should they just return an Option and let the caller decide what that should mean

Nice changes! I like the change where now default is Optional, so I don't have to handle "special case" of default value later in code! According your question, now it feels like there are kinda two scopes of Optional and they are overlapping, which might make things a bit confusing. The first scope of optional just allows to provide a default value, but only if you want to. I think it's very good and straightforward. In this case Error is needed to indicate - there is no provided value and no default to fallback. The second scope is not about default values but about optional flags themselves (if I understood correctly). So the second scope might give a possibility to not have a flag at all. In this case output type of flag parser is Optional. Not sure it's easy to parametrize output type this way, don't have a lot of experience with language yet.