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

all <- FALSE
more <- FALSE

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

usage <- function() {
    cat("Usage: summarize-check-CRAN-incoming-timings [options] [DIR]",
        "",
        "Summarize KH CRAN incoming check timings.",
        "",
        "Options:",
        "  -h, --help     print short help message and exit",
        "  -a, --all      also summarize the reverse dependencies checked",
        "  -m, --more     also summarize check example timings (if available)",
        "  -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("-a", "--all"))) {
    all <- TRUE
    args <- args[!ind]
}
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]
}

tools::summarize_check_packages_in_dir_timings(dir, all, more)