| 65 | } |
| 66 | |
| 67 | func runValidate(cmd *cobra.Command, args []string) error { |
| 68 | flags := GetGlobalFlags() |
| 69 | |
| 70 | scanDir := ResolveScanDir(args) |
| 71 | |
| 72 | // Create scanner and scan for tasks |
| 73 | taskScanner := scanner.NewScanner(scanDir, flags.Verbose, flags.IgnoreDirs) |
| 74 | result, err := taskScanner.Scan() |
| 75 | if err != nil { |
| 76 | return fmt.Errorf("scan failed: %w", err) |
| 77 | } |
| 78 | |
| 79 | tasks := result.Tasks |
| 80 | |
| 81 | // Report scan errors if any |
| 82 | if len(result.Errors) > 0 { |
| 83 | if !flags.Quiet { |
| 84 | fmt.Fprintf(os.Stderr, "Warning: encountered %d errors during scan:\n", len(result.Errors)) |
| 85 | for _, scanErr := range result.Errors { |
| 86 | fmt.Fprintf(os.Stderr, " %s: %v\n", scanErr.FilePath, scanErr.Error) |
| 87 | } |
| 88 | fmt.Fprintln(os.Stderr) |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | // Scan archive directories for task IDs to avoid false-positive dependency errors |
| 93 | v := validator.NewValidator(validateStrict) |
| 94 | if externalIDs := collectArchivedIDs(taskScanner); len(externalIDs) > 0 { |
| 95 | v.SetExternalIDs(externalIDs) |
| 96 | } |
| 97 | |
| 98 | // Run validation |
| 99 | validationResult := v.Validate(tasks) |
| 100 | validateConfig(v, validationResult, tasks) |
| 101 | |
| 102 | // Output results |
| 103 | switch validateFormat { |
| 104 | case "json": |
| 105 | if err := outputValidationJSON(validationResult); err != nil { |
| 106 | return err |
| 107 | } |
| 108 | case "text", "table": |
| 109 | outputValidationText(validationResult, flags.Quiet) |
| 110 | default: |
| 111 | return ValidateFormat(validateFormat, []string{"text", "table", "json"}) |
| 112 | } |
| 113 | |
| 114 | // Determine exit code |
| 115 | if !validationResult.IsValid() { |
| 116 | os.Exit(ExitError) |
| 117 | } else if validateStrict && validationResult.HasWarnings() { |
| 118 | os.Exit(ExitValidationWarning) |
| 119 | } |
| 120 | |
| 121 | return nil |
| 122 | } |
| 123 | |
| 124 | // outputValidationText outputs validation results in human-readable text format |