77# This file may not be copied, modified, or distributed except according to
88# those terms.
99
10+ import os
1011import ../../ confutils
1112
1213const defaultEth2TcpPort = 9000
13- const defaultDescOverride = " overridden "
14+ const defaultDescOverride = " ok "
1415
1516type DisString = distinct string
1617type NoDollar = distinct string
1718
1819proc `$` (s: DisString ): string =
1920 # this should show in the help message
20- " foobar "
21+ " ok "
2122
2223proc completeCmdArg (T: type DisString , val: string ): seq [string ] =
2324 completeCmdArg (string , val)
@@ -31,6 +32,18 @@ proc completeCmdArg(T: type NoDollar, val: string): seq[string] =
3132proc parseCmdArg (T: type NoDollar , s: string ): T =
3233 parseCmdArg (string , s).NoDollar
3334
35+ proc runtimeVal (): string =
36+ # do something that's not available at comptime
37+ {.cast (raises: []).}:
38+ discard getCurrentProcessId ()
39+ " ok"
40+
41+ proc canRaise (): string {.raises : [ValueError ].} =
42+ # do something that's not available at comptime
43+ if false :
44+ raise (ref ValueError )(msg: " never raised" )
45+ " bad"
46+
3447type
3548 TestConf = object
3649 opt1 {.
4154
4255 opt2 {.
4356 defaultValue : defaultEth2TcpPort
44- # defaultValueDesc: $defaultEth2TcpPort
4557 desc: " tcp port 2"
4658 name: " opt2" }: int
4759
4860 opt3 {.
49- defaultValue : defaultEth2TcpPort
61+ defaultValue : " bad "
5062 defaultValueDesc: defaultDescOverride
51- desc: " tcp port 3 "
52- name: " opt3" }: int
63+ desc: " const default value desc "
64+ name: " opt3" }: string
5365
5466 opt4 {.
55- defaultValue : defaultEth2TcpPort
56- defaultValueDesc: " overridden "
57- desc: " tcp port 4 "
58- name: " opt4" }: int
67+ defaultValue : " bad "
68+ defaultValueDesc: " ok "
69+ desc: " literal default value desc "
70+ name: " opt4" }: string
5971
6072 opt5 {.
61- defaultValue : DisString (" this should not show in the help message " )
73+ defaultValue : DisString (" bad " )
6274 desc: " distinct string"
6375 name: " opt5" }: DisString
6476
6880 name: " opt6" }: NoDollar
6981
7082 opt7 {.
71- defaultValue : NoDollar (" default " )
72- defaultValueDesc: " overridden "
73- desc: " no dollar func defined"
83+ defaultValue : NoDollar (" bad " )
84+ defaultValueDesc: " ok "
85+ desc: " no dollar func defined with default desc "
7486 name: " opt7" }: NoDollar
7587
88+ opt8 {.
89+ defaultValue : runtimeVal ()
90+ desc: " runtime value"
91+ name: " opt8" }: string
92+
93+ opt9 {.
94+ defaultValue : " bad"
95+ defaultValueDesc: runtimeVal ()
96+ desc: " runtime value"
97+ name: " opt9" }: string
98+
99+ opt10 {.
100+ defaultValue : " bad"
101+ defaultValueDesc: runtimeVal () & " concat"
102+ desc: " runtime value"
103+ name: " opt10" }: string
104+
105+ opt11 {.
106+ defaultValue : canRaise ()
107+ defaultValueDesc: " ok"
108+ desc: " default value can raise but default desc won't"
109+ name: " opt11" }: string
110+
111+ opt12 {.
112+ defaultValue : config.opt11
113+ desc: " default is config.opt11"
114+ name: " opt12" }: string
115+
116+ opt13 {.
117+ defaultValue : config.opt11
118+ defaultValueDesc: " ok"
119+ desc: " default is config.opt11 with default desc"
120+ name: " opt13" }: string
121+
76122let c = TestConf .load (termWidth = int .high)
0 commit comments