totptool/cmds/code.nim

24 lines
486 B
Nim

import otp
import os
const codeUsage* =
"""Usage: totptool code <name>
This will generate a TOTP code for the given secret
name in the secret store.
"""
proc code*(root: string, args: seq[string]) =
try:
var
keyFileName = args[0]
fin = open root / keyFileName
key = fin.readLine
totp = newTotp key
echo totp.now()
except:
echo getCurrentExceptionMsg()
quit "Couldn't do that for " & args[0] & ". Does that machine exist in the store?"