diff --git a/totptool.nim b/totptool.nim index 71b1526..b4272a2 100644 --- a/totptool.nim +++ b/totptool.nim @@ -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()