File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ package main
1919import (
2020 "context"
2121 "os"
22+ "strings"
2223
2324 "github.com/sirupsen/logrus"
2425
@@ -72,6 +73,26 @@ func main() {
7273 commands .IssueUnsupportedHookWarning (logger , cmd )
7374 return nil
7475 },
76+ // Handle usage errors to catch unrecognized hooks with flags
77+ OnUsageError : func (ctx context.Context , cmd * cli.Command , err error , isSubcommand bool ) error {
78+ // Check if this is a "flag provided but not defined" error
79+ errMsg := err .Error ()
80+ if strings .HasPrefix (errMsg , "flag provided but not defined: " ) {
81+ // Get the arguments to check if the first one is an unrecognized command
82+ args := cmd .Args ().Slice ()
83+ if len (args ) > 0 {
84+ potentialCmd := args [0 ]
85+ // Check if it's not a recognized subcommand
86+ if cmd .Command (potentialCmd ) == nil {
87+ // This is an unrecognized hook with flags
88+ commands .IssueUnsupportedHookWarning (logger , cmd )
89+ return nil // Suppress the error and exit cleanly
90+ }
91+ }
92+ }
93+ // For other errors, return the error as-is
94+ return err
95+ },
7596 // Define the subcommands
7697 Commands : commands .New (logger ),
7798 Flags : []cli.Flag {
You can’t perform that action at this time.
0 commit comments