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