add test for overriding error

This commit is contained in:
Daylin Morgan 2025-01-28 15:10:03 -06:00
parent 02aefc5d18
commit fe3c7c141f
Signed by: daylin
GPG key ID: 950D13E9719334AD
5 changed files with 23 additions and 2 deletions

View file

@ -2,8 +2,9 @@ import std/os except getCurrentDir
import std/[strformat, strutils] import std/[strformat, strutils]
task test, "run tests": task test, "run tests":
selfExec "r tests/tbbansi.nim" const testDir = thisDir() / "tests"
selfExec "r tests/cli/tester.nim" selfExec fmt"r {testDir}/tbbansi.nim"
selfExec fmt"r {testDir}/cli/tester.nim"
task develop, "install cligen for development": task develop, "install cligen for development":
exec "nimble install -l 'cligen@1.7.5'" exec "nimble install -l 'cligen@1.7.5'"

View file

@ -827,6 +827,7 @@ func subCmdsArray(cfg: CliCfg): NimNode =
(`cmd`, `aliases`, `desc`) (`cmd`, `aliases`, `desc`)
# is this one necessary? # is this one necessary?
proc hwylCliError*(msg: BbString) = proc hwylCliError*(msg: BbString) =
quit $(bb("error ", "red") & msg) quit $(bb("error ", "red") & msg)

6
tests/cli/clis/base.nim Normal file
View file

@ -0,0 +1,6 @@
import hwylterm, hwylterm/hwylcli
hwylCli:
name "base"
run:
echo "a base cli"

View file

@ -0,0 +1,10 @@
import hwylterm, hwylterm/hwylcli
proc hwylCliError*(msg: string) =
stderr.write "override the default error\n"
quit $(bb("error ", "red") & bb(msg))
hwylCli:
name "base"
run:
echo "a base cli"

View file

@ -111,3 +111,6 @@ postSub from root!
inside sub c inside sub c
""", """,
) )
failWithArgs(
"errorOverride", "--flag","override the default error\nerror unknown flag: flag"
)