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