|
12 | 12 | import |
13 | 13 | os, |
14 | 14 | std/[enumutils, options, strutils, wordwrap], |
| 15 | + results, |
15 | 16 | stew/shims/macros, |
16 | 17 | confutils/[defs, cli_parser, config_file] |
17 | 18 |
|
18 | 19 | export |
19 | | - options, defs, config_file |
| 20 | + options, results, defs, config_file |
20 | 21 |
|
21 | 22 | const |
22 | 23 | hasSerialization = not defined(nimscript) |
@@ -633,6 +634,9 @@ proc parseCmdArg*[T]( |
633 | 634 | _: type Option[T], s: string): Option[T] {.raises: [ValueError].} = |
634 | 635 | some(parseCmdArg(T, s)) |
635 | 636 |
|
| 637 | +proc parseCmdArg*[T](_: type Opt[T], s: string): Opt[T] {.raises: [ValueError].} = |
| 638 | + Opt.some(parseCmdArg(T, s)) |
| 639 | + |
636 | 640 | template parseCmdArg*(T: type string, s: string): string = |
637 | 641 | s |
638 | 642 |
|
@@ -734,29 +738,33 @@ proc completeCmdArg*[T](_: type Option[T], val: string): seq[string] = |
734 | 738 | mixin completeCmdArg |
735 | 739 | return completeCmdArg(type(T), val) |
736 | 740 |
|
| 741 | +proc completeCmdArg*[T](_: type Opt[T], val: string): seq[string] = |
| 742 | + mixin completeCmdArg |
| 743 | + return completeCmdArg(type(T), val) |
| 744 | + |
737 | 745 | proc completeCmdArgAux(T: type, val: string): seq[string] = |
738 | 746 | mixin completeCmdArg |
739 | 747 | return completeCmdArg(T, val) |
740 | 748 |
|
741 | | -template setField[T]( |
742 | | - loc: var T, val: Option[string], defaultVal: untyped): untyped = |
| 749 | +template setField[T](loc: var T, val: Opt[string], defaultVal: untyped): untyped = |
743 | 750 | type FieldType = type(loc) |
744 | | - loc = if isSome(val): parseCmdArgAux(FieldType, val.get) |
745 | | - else: FieldType(defaultVal) |
| 751 | + loc = if val.isOk: |
| 752 | + parseCmdArgAux(FieldType, val.get) |
| 753 | + else: |
| 754 | + FieldType(defaultVal) |
746 | 755 |
|
747 | | -template setField[T]( |
748 | | - loc: var seq[T], val: Option[string], defaultVal: untyped): untyped = |
749 | | - if val.isSome: |
| 756 | +template setField[T](loc: var seq[T], val: Opt[string], defaultVal: untyped): untyped = |
| 757 | + type FieldType = type(loc) |
| 758 | + if val.isOk: |
750 | 759 | loc.add parseCmdArgAux(type(loc[0]), val.get) |
751 | 760 | else: |
752 | | - type FieldType = type(loc) |
753 | 761 | loc = FieldType(defaultVal) |
754 | 762 |
|
755 | 763 | func makeDefaultValue*(T: type): T = |
756 | 764 | default(T) |
757 | 765 |
|
758 | 766 | func requiresInput*(T: type): bool = |
759 | | - not ((T is seq) or (T is Option) or (T is bool)) |
| 767 | + not ((T is seq) or (T is Option) or (T is Opt) or (T is bool)) |
760 | 768 |
|
761 | 769 | func acceptsMultipleValues*(T: type): bool = |
762 | 770 | T is seq |
@@ -811,7 +819,7 @@ proc generateFieldSetters(RecordType: NimNode): NimNode = |
811 | 819 | .} = |
812 | 820 | return completeCmdArgAux(`fixedFieldType`, val) |
813 | 821 |
|
814 | | - proc `setterName`(`configVar`: var `RecordType`, val: Option[string]) {. |
| 822 | + proc `setterName`(`configVar`: var `RecordType`, val: Opt[string]) {. |
815 | 823 | nimcall |
816 | 824 | gcsafe |
817 | 825 | sideEffect |
@@ -1070,7 +1078,7 @@ proc loadImpl[C, SecondarySources]( |
1070 | 1078 | {.push warning[BareExcept]:off.} |
1071 | 1079 |
|
1072 | 1080 | try: |
1073 | | - fieldSetters[setterIdx][1](conf, some(cmdLineVal)) |
| 1081 | + fieldSetters[setterIdx][1](conf, Opt.some(cmdLineVal)) |
1074 | 1082 | inc fieldCounters[setterIdx] |
1075 | 1083 | except: |
1076 | 1084 | fail("Error while processing the ", |
@@ -1293,7 +1301,7 @@ proc loadImpl[C, SecondarySources]( |
1293 | 1301 | # there is nothing left to do here. |
1294 | 1302 | discard |
1295 | 1303 | elif opt.hasDefault: |
1296 | | - fieldSetters[opt.idx][1](conf, none[string]()) |
| 1304 | + fieldSetters[opt.idx][1](conf, Opt.none(string)) |
1297 | 1305 | elif opt.required: |
1298 | 1306 | fail "The required option '" & opt.name & "' was not specified" |
1299 | 1307 | except ValueError as err: |
|
0 commit comments