totptool/cmds/code.nim

31 lines
581 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 help*() =
echo codeUsage
quit 2
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?"