30 lines
758 B
Nim
Raw Normal View History

2020-06-05 17:09:05 +03:00
import std/parseutils
import stew/shims/net as stewNet
export stewNet
export ValidIpAddress
func parseCmdArg*(T: type ValidIpAddress, s: string): T =
2023-02-15 15:26:53 +07:00
ValidIpAddress.init(s)
func completeCmdArg*(T: type ValidIpAddress, val: string): seq[string] =
# TODO: Maybe complete the local IP address?
@[]
func parseCmdArg*(T: type Port, s: string): T =
template fail =
raise newException(ValueError,
2020-10-09 16:29:48 +03:00
"The supplied port must be an integer value in the range 1-65535")
var intVal: int
let parsedChars = try: parseInt(s, intVal)
except CatchableError: fail()
2020-10-09 16:29:48 +03:00
if parsedChars != len(s) or intVal < 1 or intVal > 65535:
fail()
return Port(intVal)
func completeCmdArg*(T: type Port, val: string): seq[string] =
@[]