(import (scheme base)
        (scm fs)
        (scm io)
        (scm list)
        (scm module))

(define script-dir (directory-name (absolute-path script-name)))
(define base-dir (directory-name script-dir))
(module-search-path! (list (join-path base-dir "scm")))

(import (splg utils)
        (splg options)
        (splg grouper)
        (splg testcase))

(define (display-help)
  (format #t "Testcase mode:~%")
  (display-testcase-help)
  (format #t "Common options:~%")
  (format #t "--cfg-dir <path>~%")
  (format #t "--input <path>           (only with --create-testcase-for)~%")
  (format #t "--input-dir <path>~%")
  (format #t "--input-file <path>~%")
  (format #t "--output <dir>           (only with --create-testcase-for;~%")
  (format #t "                          default: current directory)~%")
  (format #t "--release <release>~%")
  (format #t "--spitalliste <file>~%")
  (format #t "--sl <string>~%")
  (format #t "    add an inline spitalliste entry; format:~%")
  (format #t "      burnr,plz,standort,referenz,kanton,year[,splg[:vfrom[:vto]],...]~%")
  (format #t "    repeatable to add multiple hospital entries~%")
  (format #t "--with-log~%")
  (format #t "--wohnkanton-override <kanton>~%")
  (format #t "--help~%"))

(let ((args script-arguments))
  (cond
   ((or (null? args) (member "--help" args))
    (display-help))
   (else
    (let ((options (parse-testcase-options args base-dir)))
      (cond
       ((not options) 1)
       ((get-property options 'testcase-file)
        (let ((opts (set-option options 'grouper-version grouper-version)))
          (replay-testcase opts
                           (get-property opts 'testcase-file))))
       ((and (get-property options 'testcase-burnr)
             (get-property options 'testcase-fallid))
        (let ((opts (set-option options 'grouper-version grouper-version)))
          (create-testcase-for opts
                               (get-property opts 'testcase-burnr)
                               (get-property opts 'testcase-fallid))))
       (else
        (format #t "Specify --create-testcase-for <burnr> <fallid> or --testcase <file>~%")
        1))))))
