From 938131c6cd35f4103f1300130e7931fb0379e57d Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Sun, 17 Nov 2024 12:24:39 -0600 Subject: [PATCH] add key val --- src/hwylterm/hwylcli.nim | 27 +++++++++++++++++++++++++++ test.nim | 4 ---- tests/example.nim | 9 ++++----- 3 files changed, 31 insertions(+), 9 deletions(-) delete mode 100644 test.nim diff --git a/src/hwylterm/hwylcli.nim b/src/hwylterm/hwylcli.nim index 51842f4..28fa01e 100644 --- a/src/hwylterm/hwylcli.nim +++ b/src/hwylterm/hwylcli.nim @@ -138,6 +138,10 @@ proc bb*(cli: HwylCliHelp): BbString = type Count* = object ## Count type for an incrementing flag val*: int + KV*[X,Y] = object ## basic key value type + key*: X + val*: Y + KVString* = KV[string, string] type CliSetting* = enum @@ -752,6 +756,29 @@ proc parse*(p: OptParser, target: var Count) = else: inc target.val +proc extractKey(p: var OptParser): string = + var i: int + for c in p.val: + if c notin {'=',':'}: inc i + else: break + if i == p.val.len: + hwylCliError( + "failed to parse key val flag" & + "\nkey: " & p.key.bb("bold") & + "\nval: " & p.val.bb("bold") & + "\ndid you include a separator (= or :)?" + ) + else: + result = p.val[0..