validateDocsFlattenSource enforces that exactly one of root|repo|url is set and sanity-checks the url source (scheme + non-negative bounds).
(out *docsFlattenArgs)
| 363 | // validateDocsFlattenSource enforces that exactly one of root|repo|url is set |
| 364 | // and sanity-checks the url source (scheme + non-negative bounds). |
| 365 | func validateDocsFlattenSource(out *docsFlattenArgs) error { |
| 366 | sources := 0 |
| 367 | for _, set := range []bool{out.Root != "", out.Repo != "", out.URL != ""} { |
| 368 | if set { |
| 369 | sources++ |
| 370 | } |
| 371 | } |
| 372 | if sources == 0 { |
| 373 | return errors.New(`one of "root", "repo" or "url" is required`) |
| 374 | } |
| 375 | if sources > 1 { |
| 376 | return errors.New(`"root", "repo" and "url" are mutually exclusive — set exactly one`) |
| 377 | } |
| 378 | if out.URL == "" { |
| 379 | return nil |
| 380 | } |
| 381 | if _, err := validateWebTarget(out.URL); err != nil { |
| 382 | return fmt.Errorf("invalid url %q: %w", out.URL, err) |
| 383 | } |
| 384 | if out.MaxPages <= 0 { |
| 385 | out.MaxPages = 50 |
| 386 | } |
| 387 | if out.MaxDepth < 0 { |
| 388 | out.MaxDepth = 0 |
| 389 | } |
| 390 | return nil |
| 391 | } |
| 392 | |
| 393 | // isValidGitBranch enforces the subset of git-check-ref-format rules that |
| 394 | // matters before handing the value to a subprocess: no flag-like leading |
no test coverage detected