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