MCPcopy Create free account
hub / github.com/diillson/chatcli / validateDocsFlattenSource

Function validateDocsFlattenSource

cli/plugins/builtin_docsflatten.go:365–391  ·  view source on GitHub ↗

validateDocsFlattenSource enforces that exactly one of root|repo|url is set and sanity-checks the url source (scheme + non-negative bounds).

(out *docsFlattenArgs)

Source from the content-addressed store, hash-verified

363// validateDocsFlattenSource enforces that exactly one of root|repo|url is set
364// and sanity-checks the url source (scheme + non-negative bounds).
365func 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

Callers 1

parseDocsFlattenArgsFunction · 0.85

Calls 2

validateWebTargetFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected