add when isMainModule

This commit is contained in:
Christine Dodrill 2016-01-28 14:00:42 -08:00
parent 0ff50fcbe4
commit 4bec75a3b6
1 changed files with 45 additions and 44 deletions

View File

@ -38,12 +38,13 @@ proc writeVersion() =
echo gitlog
quit 1
var
when isMainModule:
var
totpRoot: string = getHomeDir() / "life" / "crypto" / "totp"
command: string
args: seq[string]
for kind, key, val in getopt():
for kind, key, val in getopt():
case kind
of cmdArgument:
if command == nil:
@ -71,21 +72,21 @@ for kind, key, val in getopt():
of cmdEnd: assert(false) # cannot happen
if command == nil:
if command == nil:
writeHelp()
else: discard
else: discard
if not existsDir(totpRoot):
if not existsDir(totpRoot):
totpRoot.createDir
echo "Created totp root " & totpRoot
case command
of "code":
case command
of "code":
code(totpRoot, args)
of "newSecret":
of "newSecret":
newSecret(totpRoot, args)
of "ls":
of "ls":
ls(totpRoot, args)
else:
else:
echo "Command " & command & " not found."
writeHelp()