From b43c352112ef41fa1dfd4deaf68fea260c39dc92 Mon Sep 17 00:00:00 2001 From: Dinushi Dhananjani Date: Thu, 25 Jun 2026 11:27:55 +0530 Subject: [PATCH] fix: validate defaults to sre.yaml when no file argument given Users can now run 'burnless validate' in any directory containing an sre.yaml file without specifying the filename explicitly. Explicit path still works: 'burnless validate path/to/sre.yaml' Closes #UX-1 --- internal/cli/validate.go | 9 ++++++--- internal/cli/validate_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/internal/cli/validate.go b/internal/cli/validate.go index 1adfee5..6f3a623 100644 --- a/internal/cli/validate.go +++ b/internal/cli/validate.go @@ -11,16 +11,19 @@ import ( // NewValidateCmd creates the "burnless validate" command. func NewValidateCmd() *cobra.Command { return &cobra.Command{ - Use: "validate ", + Use: "validate [file]", Short: "Validate an sre.yaml file", - Args: cobra.ExactArgs(1), + Args: cobra.MaximumNArgs(1), SilenceUsage: true, RunE: runValidate, } } func runValidate(cmd *cobra.Command, args []string) error { - path := args[0] + path := "sre.yaml" + if len(args) > 0 { + path = args[0] + } cfg, err := config.Load(path) if err != nil { diff --git a/internal/cli/validate_test.go b/internal/cli/validate_test.go index 12f8ff2..cdd7d39 100644 --- a/internal/cli/validate_test.go +++ b/internal/cli/validate_test.go @@ -51,3 +51,32 @@ func TestRunValidate_MissingFile(t *testing.T) { t.Fatal("expected error for missing file, got nil") } } + +func TestRunValidate_DefaultFile(t *testing.T) { + // change to a temp dir with a valid sre.yaml + tmp := t.TempDir() + sre := ` +service: payments-api +slos: + - name: availability + target: 99.9 + window: 30d +` + if err := os.WriteFile(filepath.Join(tmp, "sre.yaml"), []byte(sre), 0o644); err != nil { + t.Fatalf("failed to write sre.yaml: %v", err) + } + + // change working directory to temp dir + orig, _ := os.Getwd() + defer func() { _ = os.Chdir(orig) }() + if err := os.Chdir(tmp); err != nil { + t.Fatalf("failed to chdir: %v", err) + } + + // run validate with NO arguments — should find sre.yaml automatically + cmd := NewValidateCmd() + cmd.SetArgs([]string{}) + if err := cmd.Execute(); err != nil { + t.Fatalf("expected no error with default sre.yaml, got: %v", err) + } +}