totptool/totptool.nim

69 lines
1.4 KiB
Nim

import commandeer
import os
# Subcommands
import cmds/code
import cmds/newSecret
import cmds/ls
const usageHelp =
"""Usage: totptool [options] <command> [args]
Options:
-h --help Show this screen
-r --root=path Use path as the totp root for secrets
-v --version Show version of totptool
Subcommands:
code <name>
Generate a two-factor auth code for <name>
newSecret <name>
Generate a new two-factor auth secret for
<name>
ls
List all the names of the secrets that
totptool tracks
"""
proc writeHelp() =
echo usageHelp
quit 2
proc writeVersion(): string =
const
gitlog = staticExec "git log -1"
return gitlog
commandline:
subcommand codecmd, "code":
arguments name, string
exitoption "help", "h", codeUsage
subcommand newSecretcmd, "newSecret":
arguments newSecretName, string
exitoption "help", "h", newSecretUsage
subcommand lscmd, "ls":
exitoption "help", "h", lsUsage
option root, string, "root", "r", getHomeDir() / "life" / "crypto" / "totp"
exitoption "help", "h", usageHelp
exitoption "version", "v", writeVersion()
errormsg "Invalid state or input"
if not existsDir(root):
quit "Cannot use key store " & root
if codecmd:
code.code(root, name)
elif newSecretcmd:
newSecret.newSecret(root, newSecretName)
elif lscmd:
ls(root, @[])
else:
quit usageHelp