#!/usr/bin/env julia

# process arguments
help = false
reports = String[]
i = 1
while i <= length(ARGS)
    if ARGS[i] == "-h"
        global help = true
    else
        push!(reports, ARGS[i])
    end
        
    global i += 1
end

ok = true
if length(reports) != 2
    global ok = false
    @error "Expected precisely 2 reports to compare"
end

if !ok
    global help = true
end

if help
    println("""Usage: fbcmt-run-frog [-h|--help] <report1> <report2>""")
    exit(ok ? 0 : 1)
end

if !isdir(reports[1]) || !isdir(reports[2])
    @error "reports must be stored in directories"
    global ok = false
end

if !ok
    exit(1)
end

# try to set up the environment
import Pkg
ips = Set(pkg.name for (_,pkg) = Pkg.dependencies())
inst_missing(x) = if !(x in ips)
    @info "Missing package '$x', trying to auto-install..."
    Pkg.add(x)
end
inst_missing("FBCModelTests")

import FBCModelTests.FROG

@info "Initialization done, starting FROG..." reports

# run the FROG
FROG.compare_reports(reports[1], reports[2])
