juancarlospaco / cliche

AutoMagic CLI argument parsing is cliche

Home Page:https://juancarlospaco.github.io/cliche

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hardcoded parse logic

beef331 opened this issue · comments

Presently the logic to parse types is hardcoded https://github.com/juancarlospaco/cliche/blob/nim/src/cliche.nim#L122-L139 . Is there any specific reason this does not use a generic interface like the following?

proc parseCommand[T](input: openarray[char]): T

This would enable support for any user type, without any added support from you.

The idea was to parse Primitives with decent performance for any targets,
not so much complex big types or any arbitrary unstructured data,
but without generating a wall of text in the expansion.

Also to keep the APIs simple in the usage, like if you have to pass too complex or nested data,
maybe just use something like --config=config.json or similar.

What would you put inside that proc ?
Just the same of the lines https://github.com/juancarlospaco/cliche/blob/nim/src/cliche.nim#L122-L139 ?

I am not complaining just wondering. PR are welcome too.

It would not be a single proc it'd be one for each type so you'd have:

import std/parseutils

proc parseCommand(oa: openarray[char], T: typedesc[bool]): T =
  parseBool(oa) # 1.7.x only sorry :P 

proc parseCommand(oa: openarray[char], T: typedesc[int]): T = 
  parseint(oa) # 1.7.x only sorry :P 

This would allow support for user defined data types, and make it less tedious to add new first class types.