From 7ef7f8acc9d6437cc466b9e17687dd52ce33a531 Mon Sep 17 00:00:00 2001 From: maxlandon Date: Thu, 7 Sep 2023 00:44:47 +0200 Subject: [PATCH] Fix recursive command filtering --- commands/readline/set.go | 10 ++++------ menu.go | 8 ++++++-- run.go | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/commands/readline/set.go b/commands/readline/set.go index 7f8f49b..53c66ad 100644 --- a/commands/readline/set.go +++ b/commands/readline/set.go @@ -15,12 +15,10 @@ import ( "github.com/reeflective/readline/inputrc" ) -var ( - // We here must assume that all bind changes during the lifetime - // of the binary are all made by a single readline application. - // This config only stores the vars/binds that have been changed. - cfgChanged = inputrc.NewConfig() -) +// We here must assume that all bind changes during the lifetime +// of the binary are all made by a single readline application. +// This config only stores the vars/binds that have been changed. +var cfgChanged = inputrc.NewConfig() // Set returns a command named `set`, for manipulating readline global options. func Set(shell *readline.Shell) *cobra.Command { diff --git a/menu.go b/menu.go index 14ed949..e0f59c6 100644 --- a/menu.go +++ b/menu.go @@ -215,7 +215,6 @@ func (m *Menu) CheckIsAvailable(cmd *cobra.Command) error { "cmd": cmd, "filters": filters, }) - if err != nil { return err } @@ -245,7 +244,12 @@ func (m *Menu) ActiveFiltersFor(cmd *cobra.Command) []string { } } - return filters + if len(filters) > 0 { + return filters + } + + // Any parent that is hidden make its whole subtree hidden also. + return m.ActiveFiltersFor(cmd.Parent()) } // SetErrFilteredCommandTemplate sets the error template to be used diff --git a/run.go b/run.go index b14a7df..a50c0ce 100644 --- a/run.go +++ b/run.go @@ -146,7 +146,7 @@ func (c *Console) execute(menu *Menu, args []string, async bool) (err error) { // Find the target command: if this command is filtered, don't run it. target, _, _ := cmd.Find(args) - if err := menu.CheckIsAvailable(target); err != nil { + if err = menu.CheckIsAvailable(target); err != nil { return err }