#! /usr/bin/Rscript --default-packages=NULL
### -*- R -*-

R_scripts_dir <- file.path(normalizePath("~"), "lib", "R", "Scripts")

more <- FALSE

dir <- file.path(normalizePath("~"), "tmp", "CRAN")

usage <- function() {
    cat("Usage: summarize-check-CRAN-incoming-results [options] [DIR]",
        "",
        "Summarize KH CRAN incoming check results.",
        "",
        "Options:",
        "  -h, --help     print short help message and exit",
        "  -m, --more     also give details for checks with non-ok results",
        "  -d=DIR         use DIR as check dir (default: ~/tmp/CRAN)",
        sep = "\n"
        )
}

args <- commandArgs(trailingOnly = TRUE)

if(any(ind <- args %in% c("-h", "--help"))) {
    usage()
    q("no", runLast = FALSE)
}
if(any(ind <- args %in% c("-m", "--more"))) {
    more <- TRUE
    args <- args[!ind]
}
if(any(ind <- startsWith(args, "-d="))) {
    dir <- substring(args[ind][1L], 4L)
    args <- args[!ind]
}
if(length(args)) {
    dir <- args[1L]
}

## No point in providing a '-a' argument, as 'all = TRUE' is used by
## default.

tools::summarize_check_packages_in_dir_results(dir, full = more)