Skip to content

Commit

Permalink
set true as default value for bool flags
Browse files Browse the repository at this point in the history
Signed-off-by: George Lemon <[email protected]>
  • Loading branch information
georgelemon committed Apr 8, 2024
1 parent f12f629 commit 1305810
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/kapsis/app.nim
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,8 @@ macro commands*(x: untyped, extras: untyped = nil) =
else:
if likely(Kapsis.commands[id.key].args.hasKey(input[i].key)):
let arg = Kapsis.commands[id.key].args[input[i].key]
if arg.datatype == vtBool and input[i].val.len == 0:
input[i].val = "true" # passing a bool flag without value is set as true
collectInputData(inputValues, id.key,
input[i].key, input[i].val, arg)
add inputFlags, (input[i].key, input[i].val)
Expand Down
12 changes: 11 additions & 1 deletion src/kapsis/runtime.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import std/[tables, strutils]

from ./app import Values, Value, KapsisValueType, expandGetters
from ./app import Values, Value, KapsisValueType, KapsisPath,
getStr, getBool, getFloat, getInt, getPath,
getFilename, getDir, getMilliseconds, getSeconds,
getMinutes, getHours, getDays, getMonths, getYears,
getJson, getYaml

export Values, Value, KapsisValueType, KapsisPath,
getStr, getBool, getFloat, getInt, getPath,
getFilename, getDir, getMilliseconds, getSeconds,
getMinutes, getHours, getDays, getMonths, getYears,
getJson, getYaml

proc has*(values: Values, key: string): bool =
## Checks if `values` contains an arg by `key`
Expand Down

0 comments on commit 1305810

Please sign in to comment.