#!/bin/bash
# e8 - evidence helper

set -e

source "/home/zwelch/src/mcf/mcsh-release/install/share/mcsh/mcsh.sh"

lib_load 'doc/legal/exhibit'

######
# Text CLI

e8_text() { cmd_dispatch "$@"; }
e8_text_usage() {
	cat <<USAGE
<cmd> ...
Text Exhibit Commands:
	generate <file>+		Generates LaTeX text exhibit
	build <file>+			Generates PDF text exhibit
USAGE
}
e8_text_generate() { exhibit_text_generate "$@"; }
e8_text_build() { exhibit_text_build "$@"; }


######
# Email CLI

e8_email() { cmd_dispatch "$@"; }
e8_email_usage() {
	cat <<USAGE
<cmd> ...
Email Exhibit Commands:
	generate <file>+		Generates LaTeX image exhibit
	build <file>+			Generates PDF image exhibit
USAGE
}
e8_email_generate() { exhibit_email_generate "$@"; }
e8_email_build() { exhibit_email_build "$@"; }


######
# Image CLI

e8_image() { cmd_dispatch "$@"; }
e8_image_usage() {
	cat <<USAGE
<cmd> ...
Image Exhibit Commands:
	generate <file>+		Generates LaTeX image exhibit
	build <file>+			Generates PDF image exhibit
USAGE
}
e8_image_generate() { exhibit_image_generate "$@"; }
e8_image_build() { exhibit_image_build "$@"; }


######
# Exhibit CLI

e8_exhibit() { cmd_dispatch "$@"; }
e8_exhibit_usage() {
	cat <<USAGE
<cmd> ...
Exhibit Commands:
	generate <file>+		Generates LaTeX exhibit
	build <file>+			Generates PDF exhibit
USAGE
}
e8_exhibit_generate() { exhibit_generate "$@"; }
e8_exhibit_build() { exhibit_build "$@"; }


######
# Binder CLI

e8_binder() { cmd_dispatch "$@"; }
e8_binder_usage() {
	cat <<USAGE
<cmd> ...
Binder Commands:
	new <name>			Creates a new binder
	update <name> <file>+		Adds files to the named binder
	generate <name>			Generates the named binder
USAGE
}

e8_binder_new() { exhibit_binder_new "$@"; }
e8_binder_list() { exhibit_binder_list "$@"; }
e8_binder_update() { exhibit_binder_update "$@"; }
e8_binder_generate() { exhibit_binder_generate "$@"; }


######
# Case CLI

e8_case() { cmd_dispatch "$@"; }
e8_case_usage() {
	cat <<USAGE
Case Commands:
	update 				Updates case binders

Case Management Commands:
	list				Lists all cases
	new <case>			Creates a new case
USAGE
}

e8_case_list() { exhibit_case_list "$@"; }
e8_case_new() { for_each exhibit_case_new "$@"; }

e8_case_update() { exhibit_case_update "$@"; }
e8_case_generate() { exhibit_case_generate "$@"; }


######
# Review

e8_review() { cmd_dispatch "$@"; }
e8_review_usage() {
	cat <<EOF
<cmd> ..
Exhibit Review Commands:
	files <file>+
	grep <pattern> <file>+
	reset
EOF
}

e8_review_reset() { exhibit_review_reset "$@"; }

e8_review_files() { exhibit_review "$@"; }

e8_review_grep() {
	min_args 2 "$@"
	local pat=$1
	shift

	local tmp
	tmp=$(cmd_tempfile)
	grep -irl -e "$pat" "$@" >"$tmp"

	local -a files
	readarray -t files <"$tmp"

	exhibit_review "${files[@]}"
}


######
# Check

e8_check_doc() {
	local name=$1
	shift

	local base
	base=$(basename "$name")

	latex_document e8_check_doc_head e8_check_doc_body \
			"$base" "$@" >"$name.tex"
	latex_pdf "$name"
}

e8_check_doc_head() {
	latex_document_title "$(basename "$1")"
	latex_document_author "Gnobodi Gnows"
	latex_document_date_today
}
e8_check_doc_body() {
	latex_section "Description"
	echo "This section provides a table of contents for $(basename "$1")"
	shift
	for_each e8_check_doc_page "$@"
}
e8_check_doc_page() {
	latex_newpage
	echo "~"
}

e8_check() {
	local tdir=$cmd_tempdir
	local ext
	local -a docs
	for ext in A B C; do
		local name="$tdir/Document $ext"
		e8_check_doc "$name" "${docs[@]}"
		docs+=( "$name.pdf" )
	done
	local binder="$tdir/The Blue Binder"
	run e8_binder_new "$binder" "${docs[@]}"
#	run okular "$binder.pdf"
}


######
# Main

e8_usage() {
	cat <<USAGE
<cmd> ...
Evidence Command Groups:
	text ...			Text exhibit commands
	email ...			Email exhibit commands
	image ...			Image exhibit commands
	exhibit ...			Exhibit commands
	binder ...			Binder commands
	case ...			Case commands
USAGE
}

e8_help() {
	cat <<HELP
This tool produces evidence for court cases.
HELP
}

app_run "$@"

View the Developer Guide Index

View the Reference Manual Index


Generated on Sat Jul 8 19:27:45 PDT 2017 by mcsh d14 v0.22.0.