Added validation for cli options.
h3rald h3rald@h3rald.com
Fri, 06 Feb 2015 21:38:28 +0100
2 files changed,
18 insertions(+),
4 deletions(-)
M
lib/cli.nim
→
lib/cli.nim
@@ -3,7 +3,8 @@ parseopt2,
strutils, logging import - types + types, + utils const@@ -42,15 +43,28 @@ case kind:
of cmdLongOption, cmdShortOption: case key: of "address", "a": + if val == "": + fail(100, "Address not specified.") address = val of "port", "p": + if val == "": + fail(101, "Port not specified.") port = val.parseInt of "log", "l": - logLevel = logging.LevelNames.find(val.toUpper).Level + if val == "": + fail(102, "Log level not specified.") + try: + logLevel = logging.LevelNames.find(val.toUpper).Level + except: + fail(103, "Invalid log level '$1'" % val) of "import": + if val == "": + fail(104, "Directory to import not specified.") operation = opImport directory = val of "export": + if val == "": + fail(105, "Directory to export not specified.") operation = opExport directory = val of "purge":
M
litestore.nim
→
litestore.nim
@@ -27,11 +27,11 @@ if not LS.file.fileExists:
try: LS.file.createDatastore() except: - fail(1, "Unable to create datastore '$1'" % [LS.file]) + fail(200, "Unable to create datastore '$1'" % [LS.file]) try: LS.store = LS.file.openDatastore() except: - fail(2, "Unable to open datastore '$1'" % [LS.file]) + fail(201, "Unable to open datastore '$1'" % [LS.file]) case LS.operation: of opImport: LS.store.importDir(LS.directory)