Fix default command used for __completeNoDesc alias (#2568)

This commit is contained in:
TJ Miller 2026-01-21 18:41:42 -08:00 committed by GitHub
parent 542801926f
commit 414a085563
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 1 deletions

2
yq.go
View File

@ -12,7 +12,7 @@ func main() {
args := os.Args[1:] args := os.Args[1:]
_, _, err := cmd.Find(args) _, _, err := cmd.Find(args)
if err != nil && args[0] != "__complete" { if err != nil && args[0] != "__complete" && args[0] != "__completeNoDesc" {
// default command when nothing matches... // default command when nothing matches...
newArgs := []string{"eval"} newArgs := []string{"eval"}
cmd.SetArgs(append(newArgs, os.Args[1:]...)) cmd.SetArgs(append(newArgs, os.Args[1:]...))

View File

@ -48,6 +48,12 @@ func TestMainFunctionLogic(t *testing.T) {
if err == nil { if err == nil {
t.Error("Expected error when no command found for '__complete', but got nil") t.Error("Expected error when no command found for '__complete', but got nil")
} }
args = []string{"__completeNoDesc"}
_, _, err = cmd.Find(args)
if err == nil {
t.Error("Expected error when no command found for '__completeNoDesc', but got nil")
}
} }
func TestMainFunctionWithArgs(t *testing.T) { func TestMainFunctionWithArgs(t *testing.T) {
@ -75,6 +81,12 @@ func TestMainFunctionWithArgs(t *testing.T) {
if err == nil { if err == nil {
t.Error("Expected error with __complete command") t.Error("Expected error with __complete command")
} }
args = []string{"__completeNoDesc"}
_, _, err = cmd.Find(args)
if err == nil {
t.Error("Expected error with __completeNoDesc command")
}
} }
func TestMainFunctionExecution(t *testing.T) { func TestMainFunctionExecution(t *testing.T) {
@ -151,6 +163,28 @@ func TestMainFunctionWithCompletionCommand(t *testing.T) {
} }
} }
func TestMainFunctionWithCompletionNoDescCommand(t *testing.T) {
// Test that __complete command doesn't trigger default command logic
cmd := command.New()
args := []string{"__completeNoDesc"}
_, _, err := cmd.Find(args)
if err == nil {
t.Error("Expected error with __completeNoDesc command")
}
// The main function logic would be:
// if err != nil && args[0] != "__completeNoDesc" {
// // This should NOT execute for __completeNoDesc
// }
// Verify that __completeNoDesc doesn't trigger the default command logic
if args[0] == "__completeNoDesc" {
// This means the default command logic should NOT execute
t.Log("__completeNoDesc command correctly identified, default command logic should not execute")
}
}
func TestMainFunctionIntegration(t *testing.T) { func TestMainFunctionIntegration(t *testing.T) {
// Integration test to verify the main function logic works end-to-end // Integration test to verify the main function logic works end-to-end