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..