nat.nim: breaking dependency with 'confutils' (#609)

* nat.nim: breaking dependency with 'confutils'

The main purpose of this change is to break the dependency with
`confutils`.
This commit is contained in:
Ivan Folgueira Bande 2023-05-16 13:43:31 +02:00 committed by GitHub
parent 6e5ee490c2
commit 285da12bf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 6 deletions

View File

@ -11,11 +11,9 @@
import import
std/[options, os, strutils, times], std/[options, os, strutils, times],
stew/results, nat_traversal/[miniupnpc, natpmp], stew/results, nat_traversal/[miniupnpc, natpmp],
chronicles, json_serialization/std/net, chronos, confutils, chronicles, json_serialization/std/net, chronos,
../common/utils, ./utils as netutils ../common/utils, ./utils as netutils
export ConfigurationError
type type
NatStrategy* = enum NatStrategy* = enum
NatAny NatAny
@ -323,7 +321,7 @@ type
of true: extIp*: ValidIpAddress of true: extIp*: ValidIpAddress
of false: nat*: NatStrategy of false: nat*: NatStrategy
func parseCmdArg*(T: type NatConfig, p: string): T {.raises: [ConfigurationError].} = func parseCmdArg*(T: type NatConfig, p: string): T {.raises: [ValueError].} =
case p.toLowerAscii: case p.toLowerAscii:
of "any": of "any":
NatConfig(hasExtIp: false, nat: NatAny) NatConfig(hasExtIp: false, nat: NatAny)
@ -340,10 +338,10 @@ func parseCmdArg*(T: type NatConfig, p: string): T {.raises: [ConfigurationError
NatConfig(hasExtIp: true, extIp: ip) NatConfig(hasExtIp: true, extIp: ip)
except ValueError: except ValueError:
let error = "Not a valid IP address: " & p[6..^1] let error = "Not a valid IP address: " & p[6..^1]
raise newException(ConfigurationError, error) raise newException(ValueError, error)
else: else:
let error = "Not a valid NAT option: " & p let error = "Not a valid NAT option: " & p
raise newException(ConfigurationError, error) raise newException(ValueError, error)
func completeCmdArg*(T: type NatConfig, val: string): seq[string] = func completeCmdArg*(T: type NatConfig, val: string): seq[string] =
return @[] return @[]