Skip to content

Commit

Permalink
Fix recursive command filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlandon committed Sep 6, 2023
1 parent dc45ff2 commit 7ef7f8a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
10 changes: 4 additions & 6 deletions commands/readline/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ func (m *Menu) CheckIsAvailable(cmd *cobra.Command) error {
"cmd": cmd,
"filters": filters,
})

if err != nil {
return err
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 7ef7f8a

Please sign in to comment.