From 6a9348520272cc60fe547d6cd557b8d5617ec7bf Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Wed, 29 Jan 2025 15:35:05 -0600 Subject: [PATCH] add inferiting flag test --- tests/cli/clis/inheritFlags.nim | 32 ++++++++++++++++++++++++++++++++ tests/cli/lib.nim | 6 ++++-- tests/cli/tester.nim | 11 +++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 tests/cli/clis/inheritFlags.nim diff --git a/tests/cli/clis/inheritFlags.nim b/tests/cli/clis/inheritFlags.nim new file mode 100644 index 0000000..bdbf411 --- /dev/null +++ b/tests/cli/clis/inheritFlags.nim @@ -0,0 +1,32 @@ +import std/strformat +import hwylterm, hwylterm/hwylcli + +hwylCli: + name "base" + flags: + [global] + always "in all subcommands" + [misc] + misc1 "first misc flag" + misc2 "second misc flag" + subcommands: + [first] + ... "command with it's own flag" + flags: + first "first first flag" + run: + echo fmt"{always=},{first=}" + + [second] + ... "command with 'misc' flags" + flags: + ^[misc] + run: + echo fmt"{always=},{misc1=},{misc2=}" + + [third] + ... "command with only 'misc1' flag" + flags: + ^misc1 + run: + echo fmt"{always=},{misc1=}" diff --git a/tests/cli/lib.nim b/tests/cli/lib.nim index 957d29f..32cb126 100644 --- a/tests/cli/lib.nim +++ b/tests/cli/lib.nim @@ -43,14 +43,16 @@ proc preCompileTestModules*() = template okWithArgs*(module: string, args = "", output = "") = preCompileWorkingModule(module) + let normalizedOutput = output.strip().strip(leading = false, chars = {'\n'}).dedent() test (module & "|" & args): let (actualOutput, code) = runTestCli(module, args) check code == 0 - check output.strip().strip(leading=false, chars = {'\n'}).dedent() == actualOutput + check normalizedOutput == actualOutput template failWithArgs*(module: string, args = "", output = "") = preCompileWorkingModule(module) + let normalizedOutput = output.strip().strip(leading = false, chars = {'\n'}).dedent() test (module & "|" & args): let (actualOutput, code) = runTestCli(module, args) check code == 1 - check output.strip().strip(leading=false, chars = {'\n'}).dedent() == actualOutput + check normalizedOutput == actualOutput diff --git a/tests/cli/tester.nim b/tests/cli/tester.nim index 4e6be88..0b35c5b 100644 --- a/tests/cli/tester.nim +++ b/tests/cli/tester.nim @@ -122,6 +122,17 @@ inside sub c """, ) +suite "parent-child": + okWithArgs( + "inheritFlags", "first --always", "always=true,first=false" + ) + okWithArgs( + "inheritFlags", "second --always --misc2", "always=true,misc1=false,misc2=true" + ) + okWithArgs( + "inheritFlags", "third --misc1", "always=false,misc1=true" + ) + suite "settings": okWithArgs( "inferShort", "-i input -o output","""input=input, output=output, count=0, nancy=false, ignore=false"""