basho / clique

CLI Framework for Erlang
Apache License 2.0
147 stars 49 forks source link

Introduce spec record for args and flags, datatypes, and validators. #45

Closed seancribbs closed 9 years ago

seancribbs commented 9 years ago

This uses cuttlefish's datatype conversion routines to automatically parse kvargs and flags. This relieves the burden of conversion from the user and resolves the issue of needing to customize error messages emitted from typecast functions, because cuttlefish already provides them. See basho/clique#44.

In order to maintain the same functionality provided by typecast (for example, clique_typecast:to_node/1), an additional 'validator' option is now recognized. The validator will be called after type conversion.

While adding these features, the proplist options seemed to be complicating too much of the code, so the internal representation of an arg or flag spec was converted to a record with all the necessary fields. Users of the code will not need to change passed arguments because the record is only used internally for efficiency and clarity. Additionally, the record enables us to avoid calling list_to_atom/1 on user input in the parser, and instead use simple matching and lists:keyfind instead. All atom creation is done when registering the command, improving safety.

seancribbs commented 9 years ago

This is needed for RIAK-1425

nickelization commented 9 years ago

:+1: 55bd9f89dd8fdf958aff7451ad5690e49ad7beda

seancribbs commented 9 years ago

@borshop merge