Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix recursive command filtering #29

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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