From 186dab6d84a33359730f9a042d95a8b07a73667d Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Thu, 21 Nov 2024 09:37:37 -0600 Subject: [PATCH] pass preSub/postSub down to children commands --- src/hwylterm/hwylcli.nim | 9 +++++++-- tests/example.nim | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/hwylterm/hwylcli.nim b/src/hwylterm/hwylcli.nim index fdccffa..c40fba6 100644 --- a/src/hwylterm/hwylcli.nim +++ b/src/hwylterm/hwylcli.nim @@ -516,8 +516,13 @@ func pasrseCliAlias(cfg: var CliCfg, node: NimNode) = func propagate(c: var CliCfg) = for child in c.subcommands.mitems: - child.pre = c.preSub - child.post = c.postSub + # push the preSub to the lowest subcommand + if child.subcommands.len != 0 and child.preSub == nil: + child.preSub = c.preSub + child.postSub = c.postSub + else: + child.pre = c.preSub + child.post = c.postSub child.inheritFrom(c) propagate(child) diff --git a/tests/example.nim b/tests/example.nim index 01a73aa..f5456dd 100644 --- a/tests/example.nim +++ b/tests/example.nim @@ -25,7 +25,7 @@ hwylCli: ? "path to config file" * @["config.yml"] preSub: - echo "this is run after subcommand parsing but before its run block" + echo "this is run after subcommand parsing but before final run block" echo fmt"{yes=}, {color=}" run: echo "this is always run prior to subcommand parsing" @@ -53,6 +53,7 @@ hwylCli: flags: ^config run: + echo "hello from `example one subsub` command" echo fmt"{color=}" run: