Closed juancarlospaco closed 1 year ago
Name: Cliche
Author: Juan Carlos
Posting: New Cliche version
bool
enum
Positive
Natural
BiggestInt
BiggestFloat
int
float
parseInt
parseFloat
parseEnum
import std/strutils import cliche # Use https://nim-lang.github.io/Nim/os.html#commandLineParams type Food = enum PIZZA, TACO # Enum from CLI. # let real = commandLineParams() let fake = @["--a=1", "--v_1=9.9", "--v2=1", "--v3=2", "--v4=X", "--v5=t", "--v6=5", "--v7=true", "--food=PIZZA"] fake.getOpt (a: int.high, v_1: 3.14, v2: 9'u64, v3: -9'i64, v4: "a", v5: '4', v6: 9.Positive, v7: false, missing: 42, food: TACO) doAssert a == 1 # int doAssert v_1 == 9.9 # float doAssert v2 == 1'u64 # uint64 doAssert v3 == 2'i64 # int64 doAssert v4 == "X" # string doAssert v5 == 't' # char doAssert v6 == 5.Positive # Positive doAssert v7 == true # bool doAssert missing == 42 # missing is not in fake, fallback to default value 42. doAssert food is Food and food == PIZZA # food is Food.PIZZA
Name: Cliche
Author: Juan Carlos
Posting: New Cliche version
bool
.enum
,Positive
,Natural
,BiggestInt
,BiggestFloat
,int
,float
directly from command line.parseInt
forint
,parseFloat
forfloat
,parseEnum
forenum
, etc.