AtlatestRepositorysigil-doc
1
#!/usr/bin/env sigil2
(import (sigil core) (sigil fs) (sigil path) (sigil process) (sigil shell) (sigil string)3
(sigil doc examples) (sigil doc model) (sigil doc verify))5
(define args (script-args))6
(when (null? args)7
(error (string-append "usage: " verifier-command-contract)))8
(define manuscript (car args))9
(when (string-starts-with? manuscript "--")10
(error (string-append "usage: " verifier-command-contract)))11
(define parsed-options12
(let loop ((xs (cdr args)) (seen '()) (no-cache #f) (example #f) (project #f) (root #f))13
(if (null? xs) (vector no-cache example project root)14
(let ((option (car xs)))15
(when (member option seen) (error (string-append "sigil doc verify: duplicate option " option)))16
(cond17
((string=? option "--no-cache")18
(loop (cdr xs) (cons option seen) #t example project root))19
((member option '("--example" "--project" "--root"))20
(when (or (null? (cdr xs)) (string-starts-with? (cadr xs) "--"))21
(error (string-append "sigil doc verify: missing value for " option)))22
(let ((value (cadr xs)) (rest (cddr xs)) (next-seen (cons option seen)))23
(cond ((string=? option "--example") (loop rest next-seen no-cache value project root))24
((string=? option "--project") (loop rest next-seen no-cache example value root))25
(else (loop rest next-seen no-cache example project value)))))26
(else (error (string-append "sigil doc verify: unknown option " option))))))))27
(define no-cache? (vector-ref parsed-options 0))28
(define selected-example (vector-ref parsed-options 1))29
(define selected-project (vector-ref parsed-options 2))30
(when (and selected-example selected-project)31
(error "sigil doc verify: --example and --project are mutually exclusive"))32
(define root (or (vector-ref parsed-options 3)33
(path-dirname (or (realpath manuscript) manuscript))))34
(define cache-dir (and (not no-cache?)35
(path-join (or (getenv "XDG_CACHE_HOME") (path-join root ".cache"))36
"sigil-doc" "verify-v1")))37
(define sigil-bin (or (getenv "SIGIL_BIN") "sigil"))39
(display verifier-authority-notice)40
(newline)41
(load manuscript)42
(define loaded-document (eval 'document))43
(define all-examples (document-examples loaded-document))44
(define all-projects (document-project-checks loaded-document))45
(define verified-count 0)46
(define (print-result result)47
(set! verified-count (+ verified-count 1))48
(display (verify-result-id result))49
(display (if (verify-result-cached? result) ": cached\n" ": verified\n")))50
(if selected-project51
(let ((selected (filter (lambda (check) (string=? (project-check-id check) selected-project)) all-projects)))52
(unless (= (length selected) 1)53
(error (format "sigil doc verify: project selection ~s matched ~a checks" selected-project (length selected))))54
(print-result (verify-project-check loaded-document (car selected) root sigil-bin cache-dir no-cache?)))55
(begin56
(if selected-example57
(let ((selected (filter (lambda (example) (string=? (example-id example) selected-example)) all-examples)))58
(unless (= (length selected) 1)59
(error (format "sigil doc verify: example selection ~s matched ~a examples" selected-example (length selected))))60
(print-result (verify-example loaded-document all-examples (car selected)61
root sigil-bin cache-dir no-cache?)))62
(begin63
(for-each64
(lambda (example) (print-result65
(verify-example loaded-document all-examples example root sigil-bin cache-dir no-cache?)))66
all-examples)67
(for-each68
(lambda (check) (print-result69
(verify-project-check loaded-document check root sigil-bin cache-dir no-cache?)))70
all-projects)))71
(when (and (not selected-example) (null? all-examples) (null? all-projects))72
(error "sigil doc verify: manuscript selected zero examples/project checks"))))73
(when (= verified-count 0)74
(error "sigil doc verify: invocation verified zero specifications"))75
(display "verified-count: ")76
(display verified-count)77
(newline)