totptool/cmds/code.nim

27 lines
540 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]) =
if args.len != 1:
quit "I need a machine name"
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?"