diff --git a/yq.go b/yq.go index 239ff0fd..4572622a 100644 --- a/yq.go +++ b/yq.go @@ -12,7 +12,7 @@ func main() { args := os.Args[1:] _, _, err := cmd.Find(args) - if err != nil && args[0] != "__complete" { + if err != nil && args[0] != "__complete" && args[0] != "__completeNoDesc" { // default command when nothing matches... newArgs := []string{"eval"} cmd.SetArgs(append(newArgs, os.Args[1:]...)) diff --git a/yq_test.go b/yq_test.go index beb25ef5..7c031215 100644 --- a/yq_test.go +++ b/yq_test.go @@ -48,6 +48,12 @@ func TestMainFunctionLogic(t *testing.T) { if err == 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) { @@ -75,6 +81,12 @@ func TestMainFunctionWithArgs(t *testing.T) { if err == nil { 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) { @@ -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) { // Integration test to verify the main function logic works end-to-end