#!/usr/bin/env raku
use v6.d;
use Property::Text::Controls;
use JSON::Fast;

sub MAIN(Str $file, Bool :$html = False, Bool :$annotated = False) {
    CATCH { default { note 'Input or report failure: ' ~ .message; exit 2 } }
    die 'Choose either --html or --annotated' if $html && $annotated;
    die 'Input must be a regular file' unless $file.IO.f;
    die 'Input exceeds 1 MiB' if $file.IO.s > 1_048_576;
    my $text = $file.IO.slurp(:enc<utf8>);
    my %report = audit-text($text);
    say $annotated ?? annotate-text($text) !! $html ?? report-html(%report) !! to-json(%report,:sorted-keys);
    exit (%report<status> eq 'no_selected_controls' ?? 0 !! 1);
}
