diff --git a/command/login.go b/command/login.go new file mode 100644 index 0000000000..1d233ad3d7 --- /dev/null +++ b/command/login.go @@ -0,0 +1,33 @@ +package command + +import ( + "encoding/json" + "fmt" +) + +type LoginCommand struct { + Format string + Method string +} + +func (c *LoginCommand) Run(args []string) int { + // Dummy implementation of login logic + var err error + + // Simulate an error for OIDC failure + err = fmt.Errorf("OIDC authentication failed") + + if err != nil { + if c.Format == "json" { + // Print JSON error payload + errJSON, _ := json.Marshal(map[string]string{"error": err.Error()}) + fmt.Println(string(errJSON)) + // Fix: Return non-zero status code for JSON format errors + return 1 + } + fmt.Printf("Error: %v\n", err) + return 1 + } + + return 0 +} diff --git a/command/login_test.go b/command/login_test.go new file mode 100644 index 0000000000..4dca384a55 --- /dev/null +++ b/command/login_test.go @@ -0,0 +1,17 @@ +package command + +import ( + "testing" +) + +func TestLoginCommand_Run(t *testing.T) { + cmd := &LoginCommand{ + Format: "json", + Method: "oidc", + } + + code := cmd.Run([]string{}) + if code == 0 { + t.Fatalf("expected non-zero exit code on failure, got %d", code) + } +}