From 2686b19535d62f3e0200f9cfdbc32e5780ebf112 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Mon, 14 Sep 2015 19:22:11 -0700 Subject: [PATCH] implement ls command --- cmds/ls.nim | 18 ++++++++++++++++++ totptool.nim | 16 +++++++--------- 2 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 cmds/ls.nim diff --git a/cmds/ls.nim b/cmds/ls.nim new file mode 100644 index 0000000..58f0520 --- /dev/null +++ b/cmds/ls.nim @@ -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] diff --git a/totptool.nim b/totptool.nim index 1c771aa..019c283 100644 --- a/totptool.nim +++ b/totptool.nim @@ -4,6 +4,7 @@ import parseopt2 # Subcommands import cmds/code import cmds/gen +import cmds/ls const usageHelp = """Usage: totptool [options] [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()