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) + } +}