cliche icon indicating copy to clipboard operation
cliche copied to clipboard

Hardcoded parse logic

Open beef331 opened this issue 2 years ago • 2 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.

beef331 avatar Nov 19 '22 22:11 beef331

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.

juancarlospaco avatar Nov 19 '22 22:11 juancarlospaco

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.

beef331 avatar Nov 19 '22 23:11 beef331