From 0f8b325246092854f4b563c97c0162daf037688b Mon Sep 17 00:00:00 2001 From: Paul Wilde Date: Sat, 28 Oct 2023 21:59:00 +0100 Subject: [PATCH] adjsuted pw gen --- pw_generaturr/nimbledeps/nimbledata2.json | 4 +++ pw_generaturr/src/pw_generaturr.nim | 32 ++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 pw_generaturr/nimbledeps/nimbledata2.json diff --git a/pw_generaturr/nimbledeps/nimbledata2.json b/pw_generaturr/nimbledeps/nimbledata2.json new file mode 100644 index 0000000..6ffe1cc --- /dev/null +++ b/pw_generaturr/nimbledeps/nimbledata2.json @@ -0,0 +1,4 @@ +{ + "version": 1, + "reverseDeps": {} +} \ No newline at end of file diff --git a/pw_generaturr/src/pw_generaturr.nim b/pw_generaturr/src/pw_generaturr.nim index e6c220c..50c3047 100644 --- a/pw_generaturr/src/pw_generaturr.nim +++ b/pw_generaturr/src/pw_generaturr.nim @@ -1,11 +1,16 @@ -import ../../globurrl + +#import ../../globurrl import httpclient import json import strutils import random +import parseopt +import os var length = 4 +var number = 10 +var word_len = 5 proc getNumber(size: int = 4): string = var num = "" @@ -21,17 +26,38 @@ proc parsePw(body: string) = var p = pass.getStr.capitalizeAscii p &= getNumber(length) echo p - proc getPW() = var c = newHttpClient() try: - let resp = c.get("https://random-word-api.herokuapp.com/word?length=5") + let resp = c.get("https://random-word-api.herokuapp.com/word?number=" & $number & "&length=" & $word_len) if resp.status == $Http200: parsePw(resp.body) except: echo getCurrentExceptionMsg() +proc parseArgs() = + var p = initOptParser(commandLineParams()) + while true: + p.next() + case p.kind + of cmdEnd: break + of cmdShortOption, cmdLongOption: + if p.val == "": + #echo "Option: ", p.key + discard + else: + #echo "Option and value: ", p.key, ", ", p.val + case p.key + of "length": + word_len = parseInt(p.val) + of "number": + number = parseInt(p.val) + of cmdArgument: + #echo "Argument: ", p.key + discard + if isMainModule: + parseArgs() getPW()