implement ls command

This commit is contained in:
Christine Dodrill 2015-09-14 19:22:11 -07:00
parent 713e74060f
commit 2686b19535
2 changed files with 25 additions and 9 deletions

18
cmds/ls.nim Normal file
View File

@ -0,0 +1,18 @@
import algorithm
import os
import strutils
const lsUsage =
"""Usage: totptool ls
Shows all of the totp codes available.
"""
proc help*() =
echo lsUsage
quit 2
proc ls*(root: string, args: seq[string]) =
for file in walkFiles root / "*":
var name = file.split("/")
echo name.reversed[0]

View File

@ -4,6 +4,7 @@ import parseopt2
# Subcommands
import cmds/code
import cmds/gen
import cmds/ls
const usageHelp =
"""Usage: totptool [options] <command> [args]
@ -54,11 +55,9 @@ for kind, key, val in getopt():
case key
of "help", "h":
case command
of "code":
code.help()
of "gen":
gen.help()
of "ls": discard
of "code": code.help()
of "gen": gen.help()
of "ls": ls.help()
else:
writeHelp()
@ -78,10 +77,9 @@ if not existsDir(totpRoot):
echo "Created totp root " & totpRoot
case command
of "code":
code(totpRoot, args)
of "gen":
gen(totpRoot, args)
of "code": code totpRoot, args
of "gen": gen totpRoot, args
of "ls": ls totpRoot, args
else:
echo "Command " & command & " not found."
writeHelp()