`processArguments` now can have alternate OptParser instead of fixed one

the `processArguments` now have overloaded proc, one with opt param and one without.
the OptParser now can be passed to `opt` param.
this is useful in scenario where in test code we need to simulate something
without using real command line arguments.
This commit is contained in:
jangko 2021-04-29 12:25:13 +07:00
parent 6049073c69
commit e6d7d6188c
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
1 changed files with 5 additions and 2 deletions

View File

@ -977,7 +977,7 @@ LOGGING AND DEBUGGING OPTIONS:
]
when declared(os.paramCount): # not available with `--app:lib`
proc processArguments*(msg: var string): ConfigStatus =
proc processArguments*(msg: var string, opt: var OptParser): ConfigStatus =
## Process command line argument and update `NimbusConfiguration`.
let config = getConfiguration()
@ -994,7 +994,6 @@ when declared(os.paramCount): # not available with `--app:lib`
# The same trick is done to discPort
config.net.discPort = 0
var opt = initOptParser()
var length = 0
for kind, key, value in opt.getopt():
result = Error
@ -1033,6 +1032,10 @@ when declared(os.paramCount): # not available with `--app:lib`
if config.net.discPort == 0:
config.net.discPort = config.net.bindPort
proc processArguments*(msg: var string): ConfigStatus =
var opt = initOptParser()
processArguments(msg, opt)
proc processConfiguration*(pathname: string): ConfigStatus =
## Process configuration file `pathname` and update `NimbusConfiguration`.
result = Success