use CommandPath to catch completion subcommands

This commit is contained in:
onyx-and-iris 2026-03-29 22:55:58 +01:00
parent bfa3314ad3
commit b956f58f5e
2 changed files with 5 additions and 2 deletions

1
.gitignore vendored
View File

@ -10,6 +10,7 @@
*.dll *.dll
*.so *.so
*.dylib *.dylib
bin/
# Test binary, built with `go test -c` # Test binary, built with `go test -c`
*.test *.test

View File

@ -28,7 +28,8 @@ It allows you to add, list, and delete patterns from the exclude file easily.
This tool is particularly useful for developers who want to keep their repository clean This tool is particularly useful for developers who want to keep their repository clean
by excluding certain files or directories from version control.`, by excluding certain files or directories from version control.`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if cmd.Name() == "completion" || cmd.Name() == "help" { if strings.HasPrefix(cmd.CommandPath(), "exclude completion") ||
strings.HasPrefix(cmd.CommandPath(), "exclude help") {
return nil return nil
} }
@ -46,7 +47,8 @@ by excluding certain files or directories from version control.`,
return nil return nil
}, },
PersistentPostRunE: func(cmd *cobra.Command, args []string) error { PersistentPostRunE: func(cmd *cobra.Command, args []string) error {
if cmd.Name() == "completion" || cmd.Name() == "help" { if strings.HasPrefix(cmd.CommandPath(), "exclude completion") ||
strings.HasPrefix(cmd.CommandPath(), "exclude help") {
return nil return nil
} }