mirror of
https://github.com/mikefarah/yq.git
synced 2026-03-10 15:54:26 +00:00
Fix default command used for __completeNoDesc alias (#2568)
This commit is contained in:
parent
542801926f
commit
414a085563
2
yq.go
2
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:]...))
|
||||
|
||||
34
yq_test.go
34
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
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user